Here is an example written in vb.net
.... load xmldoc.
Dim TagDataNodes As XmlNodeList
Dim TagDataNode As XmlNode
TagDataNodes = XMLDoc.SelectNodes("//C[.='10']")
For Each TagDataNode In TagDataNodes
GetPath(TagDataNode)
Next
End Sub
Private Function GetPath(ByRef node As XmlNode) As String
Dim FullPath As String = node.Name.ToString
Dim ParentNode As XmlNode
ParentNode = node.SelectSingleNode("..")
While Not ParentNode Is Nothing
If ParentNode.SelectSingleNode("..") Is Nothing Then
FullPath = "\" + FullPath
Else
FullPath = ParentNode.Name.ToString + "\" + FullPath
End If
ParentNode = ParentNode.SelectSingleNode("..")
End While
Console.Write(FullPath & vbCrLf)
Return FullPath
End Function
Zhiv Kurilka wrote:
Thank you very much
"Martin Honnen" <ma*******@yahoo.deschrieb im Newsbeitrag
news:eh**************@TK2MSFTNGP03.phx.gbl...
Zhiv Kurilka wrote:
supposed I have xml file
<a>
<b>
<name>ggg</name>
<c>10</c>
<name>ddd</name>
</b>
<b>
<name>zzz</name>
<c>10</c>
<name>yyyy</name>
</b>
<b>
<name>zzz</name>
<c>12</c>
<name>xxxxx</name>
</b>
</a>
Lets say I need to select all nodes where c=10 and print a path of names
dim my_list as xmlnodelist =myRootNode.SelectNodes("//a/b[c='10']")
Now I need to print a path of nodes name. The result should be:
---------------------
ggg/ddd
zzz/yyy
Here is a C# example:
foreach (XmlNode b in xmlDocument.SelectNodes(@"a/b[c = '10']")) {
XmlNodeList names = b.SelectNodes("name");
for (int i = 0; i < names.Count; i++) {
if (i == names.Count - 1) {
Console.WriteLine(names[i].InnerText);
}
else {
Console.Write("{0}/", names[i].InnerText);
}
}
}
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/