Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, June 2, 2010

XML Nodes by Name

//Xml

Names>
name>
firstname>John
lastname>Smith
/Name>
name>
firstname>James
lastname>White
/Name>
/Names>

//C#

XmlDocument xml = new XmlDocument();
xml.Load(myXmlString); // suppose that myXmlString contains "..."

XmlNodeList xnList = xml.SelectNodes("/Names/Name");
foreach (XmlNode xn in xnList)
{
string firstName = xn["FirstName"].InnerText;
string lastName = xn["LastName"].InnerText;
Console.WriteLine("Name: {0} {1}", firstName, lastName);
}