Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SelectNodes and GetElementsByTagName

what are main differences between SelectNodes and GetElementsByTagName.

like image 274
Jason Avatar asked Dec 17 '22 01:12

Jason


2 Answers

SelectNodes is a .NET/MSXML-specific method that gets a list of matching nodes for an XPath expression. XPaths can select elements by tag name but can also do lots of other, more complicated selection rules.

getElementByTagName is a DOM Level 1 Core standard method available in many languages (but spelled with a capital G in .NET). It selects elements only by tag name; you can't ask it to select elements with a certain attribute, or elements with tag name a inside other elements with tag name b or anything clever like that. It's older, simpler, and in some environments faster.

like image 132
bobince Avatar answered Dec 29 '22 04:12

bobince


SelectNodes takes an XPath expression as a parameter and returns all nodes that match that expression.

GetElementsByTagName takes a tag name as a parameter and returns all tags that have that name.

SelectNodes is therefore more expressive, as you can write any GetElementsByTagName call as a SelectNodes call, but not the other way around. XPath is a very robust way of expressing sets of XML nodes, offering more ways of filtering than just name. XPath, for example, can filter by tag name, attribute names, inner content and various aggregate functions on tag children as well.

like image 27
Welbog Avatar answered Dec 29 '22 03:12

Welbog