![]() |
read from xml by tag in c#
hi
i am new to c# and xml. i have made a xml file by c# where the tags are Information,Fname,Lname,Username. now i want to read value from Fname tag and set the value in a text box. i also want to read value from Lname tag and set the value in a text box how can i do this. agile |
Re: read from xml by tag in c#
In the .Net there is a Namespace called XML where you can grab the Class XmlDocument.
Code:
XmlDocument xmlDoc = new XmlDocument();When the Xml is loaded into the XmlDocument object you can view it's attributes and element using the properties inside the XmlDocument. For more info see MSDN Documentation on XmlDocument: msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx |
Re: read from xml by tag in c#
There is another interesting feature in C# namely XML Serialization. You can read from / to a class to / from xml. A convenient way of using C# for reading and writing xml data.
|
Re: read from xml by tag in c#
Quote:
xDoc.Load(@"your_xml_file_Path.xml"); XmlNodeList Fname = xDoc.GetElementsByTagName("Fname"); XmlNodeList Lname = xDoc.GetElementsByTagName("Lname"); textBox1.Text = Fname[0].InnerText; textBox2.Text = Lname[0].InnerText; |
Re: read from xml by tag in c#
Sample coding snipet for Reading xml Using LINQ to XML conceptws
Code:
//namespace |
| All times are GMT +5.5. The time now is 10:16. |