i have a small problem using the DOM parser for XML in c#

XmlDocument doc = new XmlDocument();
XmlNodeList _list = null;
_list = doc.GetElementsByTagName("DataSource");
foreach (XmlNode node in _list)
   //some processing


over here i am able to get specific nodes using the getElementByTagName method.....
after this is done.....
how do i browse the child nodes of the nodes i've already selected......


my code selects all the DataSource nodes in the xml.....
now for each of the DataSource nodes in the list that my code fetches....
i want to get browse the child nodes.... get the value of Name...
and if there is a Property field available, then i want to get the value of Property.....

Please help.....

7 Years
Discussion Span
Last Post by arjunpk

the xml is just an example.....
the actual xml is 20 pages long.....
that is why i haven't put the original file into the question....


You can traverse child nodes quite easily in C#.

// assume here I have a DataSource node called node
foreach (XmlNode childNode in node.ChildNodes)
  string nodeValue = String.Empty;
  // use a case insensitive search on the node name
  string childNodeName = childNode.Name.ToLowerInvariant();
  if (childNodeName == "name")
    nodeValue = childNode.Value;
    // do something meaningful with the value of the node...

  else if (childNodeName == "property")
    nodeValue = childNode.Value;
    // do some other meaningful thing with the value of the node...

    // error - invalid node so do some error handling here...


Hope this helps.

Votes + Comments
thank you.. :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.