Data from Xml to textboxes


I am getting this string from Database
<Line1>W62 N692 Riveredge Drive</Line1>

I just want to save the value of different nodes to the respective textboxes in ASP.NET using C#.
What would be the best method to do that??

Who is Participating?
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, these are examples of how to do that based on the eridanix recommendation:

By using Linq to handle xml (Framework 3.5 and later):
string xml = "<Address><FirstName>Test 1</FirstName><LastName>Test 2</LastName><Line1>W62 N692 Riveredge Drive</Line1></Address>";
System.Xml.Linq.XElement address = System.Xml.Linq.XElement.Parse(xml);
string firstName = address.Element("FirstName").Value;
string lastName = address.Element("LastName").Value;
string line1 = address.Element("Line1").Value;

Open in new window

By using the System.Xml.XmlDocument class:
string xml = "<Address><FirstName>Test 1</FirstName><LastName>Test 2</LastName><Line1>W62 N692 Riveredge Drive</Line1></Address>";
System.Xml.XmlDocument xmlDocAddress = new System.Xml.XmlDocument();
string firstName = xmlDocAddress.SelectSingleNode("Address/FirstName").InnerText;
string lastName = xmlDocAddress.SelectSingleNode("Address/LastName").InnerText;
string line1 = xmlDocAddress.SelectSingleNode("Address/Line1").InnerText;

Open in new window


you can use Linq to XML.

Or the other posible solution is to parse XML using XmlDocument methods from System.Xml namespace.
Good example is here:
ASPNET_8Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.