|
-
April 3rd, 2008, 05:41 PM
#1
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.
-
April 4th, 2008, 04:56 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|