Data from Xml to textboxes

Posted on 2011-10-13
Last Modified: 2012-05-12

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??

Question by:ASPNET_8
    LVL 5

    Expert Comment


    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:
    LVL 17

    Accepted Solution

    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


    Author Closing Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now