Raoul Borges
2006-06-20 10:27:40 UTC
Ok, it's a strange question.
There is some article on the web:
http://www.devx.com/vb2themax/Tip/18823
======================================================
However, a quick look at the implementation of SelectSingleNode suggests
that using SelectNodes is often preferable. The following pseudocode shows
the internal working of SelectSingleNode:
Public Function SelectSingleNode(xpathExpr As String) As XmlNode
Dim nodes As XmlNodeList = SelectNodes(xpath)
Return nodes(0)
End Funtion
The SelectSingleNode method internally calls SelectNodes and retrieves all the
nodes that match a given XPath expression. Next it simply returns the first
selected node to the caller.
======================================================
And then, the author, Dino Esposito, asserts :
======================================================
doc.SelectSingleNode("NorthwindEmployees/Employee[position() = 1]")
======================================================
is faster than:
doc.SelectSingleNode("NorthwindEmployees/Employee")
My own take is that this is really... Ahem... Strange. My own tests show this to be
false (I compared selectSingleNode with selectNodes with the same XPath resquests,
and then with selectSingleNode with the same XPath + [position() = 1]).
I searched the net for confirmation, but found nothing but an article on the MSDN saying
the two were equivalent (but never saying they are the same code).
Could I have some external advice about all this ?
(if from someone familiar with internal workings of the MSXML, all the better !)
Thanks !
-- Raoul BORGES
P.S.: To email me, remove the Xs from my email adress.
There is some article on the web:
http://www.devx.com/vb2themax/Tip/18823
======================================================
However, a quick look at the implementation of SelectSingleNode suggests
that using SelectNodes is often preferable. The following pseudocode shows
the internal working of SelectSingleNode:
Public Function SelectSingleNode(xpathExpr As String) As XmlNode
Dim nodes As XmlNodeList = SelectNodes(xpath)
Return nodes(0)
End Funtion
The SelectSingleNode method internally calls SelectNodes and retrieves all the
nodes that match a given XPath expression. Next it simply returns the first
selected node to the caller.
======================================================
And then, the author, Dino Esposito, asserts :
======================================================
doc.SelectSingleNode("NorthwindEmployees/Employee[position() = 1]")
======================================================
is faster than:
doc.SelectSingleNode("NorthwindEmployees/Employee")
My own take is that this is really... Ahem... Strange. My own tests show this to be
false (I compared selectSingleNode with selectNodes with the same XPath resquests,
and then with selectSingleNode with the same XPath + [position() = 1]).
I searched the net for confirmation, but found nothing but an article on the MSDN saying
the two were equivalent (but never saying they are the same code).
Could I have some external advice about all this ?
(if from someone familiar with internal workings of the MSXML, all the better !)
Thanks !
-- Raoul BORGES
P.S.: To email me, remove the Xs from my email adress.