Loop through Xml file and read value of attributes.

  • Thread starter Thread starter AURADKAR
  • Start date Start date
A

AURADKAR

Guest
Hi Team,

I Have the below sample xml and I want to loop through each attribute.

<Affiliates>
<Affiliate name="FirstAffiliate">
<Mapping accounts="FirstMappingaccount" />
<Mapping accounts="SecondMappingaccount" />
</Affiliate>
<Affiliate name="SecondAffiliate" >
<Mapping accounts="Mappingaccount" />
</Affiliate>
</Affiliates>

Desired Output

FirstAffiliate

FirstMappingaccount

SecondMappingaccount

SecondAffiliate

Mappingaccount


I have done coding as below:


XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"FilePath");
XmlNodeList xnlNodes = xmldoc.SelectNodes("Affiliates/Affiliate");
foreach (XmlNode xndNode in xnlNodes)
{
XmlElement element = (XmlElement)xndNode;
string Name = xndNode.Attributes["name"].Value;
Console.WriteLine(Name);

//How to loop through mapping field//?

}


Thanks

Sushil

Continue reading...
 
Back
Top