- Home /
A node in a childnode?
i have the following XML file:
<IncidentTracker>
<IncidentType name = "Car crash" >
<Victim
Name ="John Cena"
Age ="18"
Gender = "Male"
ContractNumber ="123456789" />
</IncidentType>
</IncidentTracker>
i wrote
XmlNode root = xml.FirstChild;
if (root.HasChildNodes)
{
for( int x = 0; x < root.ChildNodes.Count; x++)
{
strInnocentTracker = root.ChildNodes[x].Attributes[0].Value;
}
}
it only return Car crash. What can i do so that it will return me all the attributes in the victim? Thanks
Comment
Best Answer
Answer by eskimojoe · Oct 31, 2013 at 01:42 AM
Please try this:
XmlNode root = xml.FirstChild;
if (root.HasChildNodes)
{
for( int x = 0; x < root.ChildNodes.Count; x++)
{
var strInnocentTracker = root.ChildNodes[x].ChildNodes;
if (strInnocentTracker != null) {
for( int x1 = 0; x1 < strInnocentTracker.ChildNodes.Count; x1++)
{
// attributes
}
}
}
}