get the name of the xml nodes using in c#

Posted by Santosh198318 under C# on 5/9/2012 | Points: 10 | Views : 1477 | Status : [Member] | Replies : 2
<?xml version="1.0" encoding="utf-8"?>
<Account>
<field name="name"></field>
<field name="new_accountscope"></field>
<field name="address1_line1">address1_line1</field>
<field name="address1_line2">address1_line2</field>
</account>
i have a xml ..now i have to pass the value and get the corresponding name ....please give the example in c#




Responses

Posted by: Sakthi.Singaravel on: 5/9/2012 [Member] Silver | Points: 25

Up
0
Down
refer this article..
www.c-sharpcorner.com/uploadfile/mahesh/readwritexmltutmelll211128200504517AM/readwritexmltutmellli21.aspx

Regards,
Singaravel M

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 5/26/2012 [Member] Bronze | Points: 25

Up
0
Down
<Names>

<Name>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Name>
<Name>
<FirstName>James</FirstName>
<LastName>White</LastName>
</Name>
</Names>



C#

XmlDocument xml = new XmlDocument();

xml.LoadXml(myXmlString); // suppose that myXmlString contains "<Names>...</Names>"

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);
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response