Groups | Blog | Home
all groups > dotnet xml > march 2006 >

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


dickster
3/24/2006 4:14:57 AM
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
dickster
3/24/2006 4:40:28 AM
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
AddThis Social Bookmark Button