SelectNodes vs. GetElementsByTagName

G

Guest

Hello All:

Does anyone know the differnce between the GetElementsByTagName method and
the SelectNodes method? I know that they take different arguments. They
also both return a NodeList. I'm wondering when would I use one vs. the
other.

TIA,
 
K

Karl Seguin

SelectNodes takes an XPath, which provides considerably more flexibility
than the simpler GetElemetsByTagName. If you simply need all elements,
reguardless of attribute values, or parent's, which have a specific tag,
then use GetElementsByTagName, otherwise, you don' thave much of a choice
but to use SelectNodes.

Not an XPath expert, but I believe that:

NodeList nodes = document.GetElementsByTagName("title");

is the same as

NodeList nodes = document.SelectNodes("//title");

but with SelectNodes, you can do stuff like:

NodeList nodes =
document.SelectNodes("/Invetory/Books/Title[@type='childrens']"); which you
obviously can't do with the first one..

Karl
 
G

Guest

Thanks Karl.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Karl Seguin said:
SelectNodes takes an XPath, which provides considerably more flexibility
than the simpler GetElemetsByTagName. If you simply need all elements,
reguardless of attribute values, or parent's, which have a specific tag,
then use GetElementsByTagName, otherwise, you don' thave much of a choice
but to use SelectNodes.

Not an XPath expert, but I believe that:

NodeList nodes = document.GetElementsByTagName("title");

is the same as

NodeList nodes = document.SelectNodes("//title");

but with SelectNodes, you can do stuff like:

NodeList nodes =
document.SelectNodes("/Invetory/Books/Title[@type='childrens']"); which you
obviously can't do with the first one..

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top