CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006
    Posts
    127

    XML Dynamic Node List

    Hello.
    I am able to read XML data from disk into strings. I obviously created these strings manually. Is there a way to achieve this dynamically?

    Code:
    XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(message);
    
                XmlNodeList name = xDoc.GetElementsByTagName("myName");
                XmlNodeList telephone = xDoc.GetElementsByTagName("myTelephone");
                XmlNodeList email = xDoc.GetElementsByTagName("myEmail");
                XmlNodeList age = xDoc.GetElementsByTagName("myAge");
                XmlNodeList sex = xDoc.GetElementsByTagName("mySex");
    
                mname = name[0].InnerText;
                mtel = telephone[0].InnerText;
                memail = email[0].InnerText;
                mage = age[0].InnerText;
                msex = sex[0].InnerText;
    Let's say at some point the XML file changes and I want to add a node for first name in the XML file. Is there a way that my C# program could read this first name into a string without me defining it previously?
    Any help is appreciated.
    Last edited by slewrate; April 3rd, 2008 at 05:44 PM.

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: XML Dynamic Node List

    Perhaps you can read the Xml document into a data set using the DataSet.ReadXml method. That way you have all the data in one place and you can access whatever you want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured