Hi !
My XML is a bit like this:
<Layers><Layer><OverlapNames> ...</OverlapNames><CommonNames> ...</CommonNames><SnapNames><SnapName Name="zzz" /><SnapName Name="yyy" /></SnapNames</Layer></Layers>
I have this initial XmlNode which returns a valid object:
XmlNode nodeLayer = xmlDoc.SelectSingleNode(String.Format("Layers/Layer[@Name=\"{0}\"]", strLayer));
Now what I want to do is try to find within this node if there is a SnapNames/SnapName with a value of, eg: zzz.
So I thought this would work (where strLayer2 is "zzz":
XmlNode nodeLayer2 = nodeLayer.SelectSingleNode(String.Format(".//SnapsNames/SnapName[@Name=\"{0}\"]", strLayer2)); // Also tried: XmlNode nodeLayer2 = nodeLayer.SelectSingleNode(String.Format("SnapsNames/SnapName[@Name=\"{0}\"]", strLayer2));
But nodeLayer2 is always null! The only way I have managed to do it so far is like this:
bool bIsSnapName = false; if (nodeLayer.HasChildNodes) { for (int i=0; i<nodeLayer.ChildNodes.Count; i++) { if (nodeLayer.ChildNodes[i].Name == "SnapNames") { XmlNode nodeSnapNames = nodeLayer.ChildNodes[i]; XmlNode nodeSnapName = nodeSnapNames.SelectSingleNode(String.Format("SnapName[@Name=\"{0}\"]", strLayer2)); if (nodeSnapName != null) { bIsSnapName = true; break; } } } }
What am I doing wrong? How can I take the nodeLayer object and return the sub node from SnapNames/SnapName where Name = "zzz"?
Thanks.