473,659 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best Practice: Loop through Nodes in NodeList vs. XPathNodeIterat or

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 XPathNodeIterat or

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

Thanks,
Vincent
Nov 11 '05 #1
1 8402
panik wrote:
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 XPathNodeIterat or


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

Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1488
by: arvindsd | last post by:
Hi all, The code below gets me a list of all the nodes within the node object called xml_tags_root. NodeList nl = xml_tags_root.getChildNodes(); The length of nodelist I get is double the number of actual elements! This is because after every element node there is text node which is (I think) the whitespace in the XML document.
4
1710
by: Larry R | last post by:
I am trying to use XPath (XSLT 1.0), EXSLT 1.1 (.Net) to select the nodelist consisting of the 'top n' nodes. THe counter is the count of item/value. Using a traditional for-each logic, the psuedo code would look something like this counter=0 maxItems=4 nodelist = nothing
1
1609
by: Sonu Kapoor | last post by:
Hi guys, I know that counting of nodes is not a big deal. But I need to do something where I cant get any solution. Here is how my xml looks like. <?xml version="1.0" encoding="utf-8"?> <CategoryList> <Category> <MainCategory ID="3">XML</MainCategory>
1
1357
by: Patrick F | last post by:
i got this xml code: <formmonthnames> <monthnames id="">January</monthnames> <monthnames id="">February</monthnames>
6
1722
by: Grant | last post by:
I have this simple xml file which wont ever get beyong 3 nodes deep. I need to get the value of the child node of any node with an id of '63'. So fir instance I would be returned 'False' from the example below. Ive attached an XML snippet and a cC# code snippet. The piece of code is not working as I am not too familiour with parsing XML files.I think I need to load the attributes into an array and loop through them to check for that...
9
6162
by: Art | last post by:
Hello, Here is a fragment of my code, which fails and I don't know why. --------------------------------- XmlDocument doc = new XmlDocument(); doc.Load(@"C:\mydoc.xml"); foreach (XmlNode objNode in doc.SelectNodes("author")) { System.WriteLine(objNode.Value.ToString()); } ---------------------------------------------------------------
2
1465
by: K B | last post by:
I bit new to this. My xml files contains the following nodes: <root> <WI Title="Test1"> <Role Name="Legal"/> <Role Name="PM"/> </WI> <WI Title="Test1"> <Role Name="Legal"/> <Role Name="Legal"/>
2
6646
by: Thirsty Traveler | last post by:
Given the XML sampe below, how would I loop through all of the borrowers in the XML document in order to process the attributes: <REQUEST_GROUP MISMOVersionID="2.1.1" InternalAccountIdentifier=""> <REQUEST RequestDatetime="2003-12-08T09:37:28> - <REQUEST_DATA> <BORROWER _FirstName="BNUM1" _LastName="LNAME1" />
14
2029
by: marfi95 | last post by:
I'm trying to iterate through a list of child nodes. It seems like to get the text value of the node, you have to do a node->getFirstChild()->getNodeValue. This being said, there is a hasChildNodes method, but if I use that, it includes the "text" nodes also, which I don't want ot include. if this is my xml: <A> <B></B>
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.