Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 2nd, 2006, 04:45 PM
Zhiv Kurilka
Guest
 
Posts: n/a
Default how to print selected nodes path

Dear all,
supposed I have xml file
root>
<a>
<name>ddd</name>
<b>
<name>ggg</name>
<c>10</c>
</b>
</a>

<a>
<name>yyyy</name>
<b>
<name>zzz</name>
<c>10</c>
</b>
</a>
<a>
<name>zzz</name>
<b>

<c>12</c>
<name>xxxxx</name>
</b>
</a>

</root>


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:
---------------------
ddd/ggg
yyyy/zzz
--------------------
Please help me. How can I do that? I have no idea how to get this info from
my_list



  #2  
Old August 3rd, 2006, 10:35 AM
dickster
Guest
 
Posts: n/a
Default Re: how to print selected nodes path

Not quite complete but this should get you on the path!

Dim node As XmlNode
Dim xdoc As New XmlDocument
Dim myStack As New Stack
xdoc.Load(<<xml from file>>)

For Each node In xdoc.SelectNodes("//a/b[c='10']")

While node.ParentNode.NodeType <XmlNodeType.Document


myStack.Push(node.SelectSingleNode("name").InnerTe xt)
node = node.ParentNode

End While

While myStack.Count 0
Console.Write(myStack.Pop)
Console.Write("/")
End While

Console.WriteLine("")
Next

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles