|
|
|
In the XmlNode class, that is the class that provides node functionality in an XMLDOM representation of an XML document, the SelectNodes (and the ancillary SelectSingleNode) method exploits the XPath query language to let you extract nodes based on logical conditions. The SelectNodes methods return a collection of XmlNode object, whereas SelectSingleNode returns only the first node that match the XPath criteria. 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: |
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. Using SelectSingleNode perhaps results in a more easily readable code, but doing so certainly does not improve the performance of the application when you need just one node. A better way to query for a single node is using a smarter XPath expression. The idea is that you place a stronger filter on the XPath expression so that it returns just the node, or the nodes, you want. For example, to get only the first node, use the following query: |
The use of SelectSingleNode in this case simply serves the purpose of returning a XmlNode object rather than an array of objects. |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|