How to loop through certain XML Nodes

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a XML document similar to:
<pre class="prettyprint <actor id="approver
<name>user</name>
</actor>
<actor id="142
<name>Kenny</name>
</actor>
...[/code]
There are other nodes beyond this that are not "actor" nodes. The thing is, I do not know how many "actor" nodes there will be within the XML file. I need to be able to loop through all of these "actor" nodes INCLUDING the "actor" portion with
its "id" attribute. I managed to use SelectNodes to grab all the "actor" nodes but cant seem to find a way to also get the information (attribute) for that node in the loop... I used something similar to this:
<pre class="prettyprint XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(StrXml);
var nodeList = xmlDoc.SelectNodes("//actor");

for (int i = 0; i < nodeList.Count; i++)
{
...loop through actor elements...
}[/code]
<br/>
Any help would be greatly appreciated!!



View the full article
 
Back
Top