Search for nodes by name in XmlDocument
Posted
by RajenK
on Stack Overflow
See other posts from Stack Overflow
or by RajenK
Published on 2010-05-09T09:47:32Z
Indexed on
2010/05/09
9:58 UTC
Read the original article
Hit count: 201
c#
|xmldocument
I'm trying to find a node by name in an XmlDocument with the following code:
private XmlNode FindNode(XmlNodeList list, string nodeName)
{
if (list.Count > 0)
{
foreach (XmlNode node in list)
{
if (node.Name.Equals(nodeName)) return node;
if (node.HasChildNodes) FindNode(node.ChildNodes, nodeName);
}
}
return null;
}
I call the function with:
FindNode(xmlDocument.ChildNodes, "somestring");
For some reason it always returns null and I'm not really sure why. Can someone help me out with this?
© Stack Overflow or respective owner