CSharp XmlDocument Reading Example

 

There are many ways to use XML, which complicated figuring this all out.  Be careful, there are multiple options for XML handling - XmlDocument and XmlReader - these are different.

This is loosly based on http://www.aspnettutorials.com/tutorials/database/XML-Csharp.aspx

 

My draft example for using XmlDocument in C#:

Create the XmlDocument object, e.g. docXML.  This holds the entire XML object, i.e. the whole "file"

docXML.LoadXml(xmlString);

Get a reference to the root element, XmlElement.  This is... like a pointer (?) 

XmlElement nodRoot = docXML.DocumentElement;

Create a list of the nodes

XmlNodeList nodItems = nodRoot.GetElementsByTagName("member");

Loop the list of nodes

for(int i = 0; i < nodItems.Count; i++)

Get the current XmlNode

XmlNode nodMember = nodItems.Item(i); 

Get the tag value that you want

Console.WriteLine("nodMember[member_id]:" + nodMember["member_id"].InnerText); // returns "nodMember[member_id]:7264"

 

 

tags: csharp, dotnet, xml, xmldocument, 

Related Scribbles:
  • C# (Csharp) Links and Resources


  • ID: 940
    Author:
    leonard
    Date Updated:
    2010-01-21 12:12:33
    Date Created:
    2010-01-21 12:09:24

    Edit

    Comments?
     >> Leonard Chan's Homepage  >> Scribble Web  >> CSharp XmlDocument Reading Example
    leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.