By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

With an XmlNode from a NodeList Can you tell where you are in the original XmlDocument

P: n/a
This problem was raised in another post

Assuming we have an XmlDocument (xDoc) that has a node (<dickster>)
randomly dispersed throughout the hierarchy.

eg
<root>
<A>
<B>
<C>
<dickster>1</dickster>
</C>
</B>
</A>
<D>
<dickster>2</dickster>
</D>
<E>
<F>
<dickster>3</dickster>
<dickster>4</dickster>
</F>
</E>
<dickster>5</dickster>
</root>
We use SelectNodes to get an XmlNodeList that mathces xpath
"//dickster"

In the problem on the other post we wanted to embed all dickster
elements in say a <temp> element

i.e.
<root>
<A>
<B>
<C>
<temp>
<dickster>1</dickster>
</temp>
</C>
</B>
</A>
<D>
<temp>
<dickster>2</dickster>
</temp>
</D>
<E>
<F>
<temp>
<dickster>3</dickster>
</temp>
<temp>
<dickster>4</dickster>
</temp>
</F>
</E>
<temp>
<dickster>5</dickster>
</temp>
</root>
How can we tell where we are in the xDoc hierarchy when we are looping
through each of the nodes in the XmlNodeList
i.e.

Dim xDoc As XmlDocument
xdoc.load(<xml>)
Dim xList As XmlNodeList = xDoc.SelectNodes("//dickster")
Dim xnode as XmlNode

For each xnode in xList
' how can xnode tell where it belongs in the xml hierarchy ???
Next
I hope this makes sense.

Original issue was raised here:
groups.google.com/group/microsoft.public.dotnet.xml/browse_thread/thread/bab743a6aab8b84d
Dickster

Mar 24 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Maybe this makes it a bit clearer:

For Each xNode In xList
Dim xEle As XmlElement = xDoc.CreateElement("temp")
xEle.AppendChild(xNode)

' now I want to replace xNode by xEle but I
' dont know how to do that because i dont know where I
' am in xDoc in order to use .ReplaceChild()
Next

Mar 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.