Simple Syntax for XML node looping
- 12th September , 2007 by Sam in .Net / C#
- 0 comments | Add my comment
Sometimes I really hate .Net blogs and C# websites.
All I wanted was the syntax to loop through the nodes of an XML document. You’d think that would be easy to find.
WRONG!
My search lead me to many long winded dissertations on to use XML for web services or someone’s home grown SAX implementation but no simple syntax that wasn’t buried in 1000 lines of code. Seriously, who is going to read 1000 lines of code in a blog post?
Anyway, I’ve distilled it below. I know it’s simple. But, I couldn’t find simple. Maybe my google skillz are lacking.
This code assumes you have “customer” nodes within your XML document and each customer has an attribute called “name”.
I realize the above code reassigns nodeValue each time through the loop, but I just wanted to show the syntax for retrieving an attribute value.

