Connecting Tech Pros Worldwide Forums | Help | Site Map

Best Practice: Loop through Nodes in NodeList vs. XPathNodeIterator

panik
Guest
 
Posts: n/a
#1: Nov 11 '05
Hi,

say I have an xml file with an X number of nodes I want to loop through (to,
for example, display each node as a HyperLink in an asp.net webpage). Which
of both is best practice:

1. Loop through a NodeList (e.g.: foreach XmlNode in XmlNodeList ... )
2. or use an XPathNodeIterator

Are there any differences in performance? Are both used for different
situations?

Thanks,
Vincent



Oleg Tkachenko
Guest
 
Posts: n/a
#2: Nov 11 '05

re: Best Practice: Loop through Nodes in NodeList vs. XPathNodeIterator


panik wrote:
[color=blue]
> say I have an xml file with an X number of nodes I want to loop through (to,
> for example, display each node as a HyperLink in an asp.net webpage). Which
> of both is best practice:
>
> 1. Loop through a NodeList (e.g.: foreach XmlNode in XmlNodeList ... )
> 2. or use an XPathNodeIterator[/color]

I assume you get XmlNodeList via SelectNodes() method. Then both approaches
are equivalent, becuase SelectNodes() is just a wrapper around
XPathNodeIterator, which provides list-like functionality.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Closed Thread


Similar .NET Framework bytes