|
-
Sep 21st, 2003, 03:31 PM
#1
Thread Starter
Lively Member
Dump a XML xpath search into a new xml.xmldocument. [RESOLVED]
I have a xml document that has a good amount of data in it...
I can execute the SelectNodes function to return a nodelist, but now I would like to dump this node list into a new xml.xmldocument object?
any thoughts???
I have tried to loop thur each node and place it into a dataset and merge it with the next node, but the results are not what I intended on. the New xml.xmldocument needs to have the same structure as the original.
Last edited by Evad; Sep 22nd, 2003 at 02:10 PM.
-
Sep 22nd, 2003, 11:47 AM
#2
Thread Starter
Lively Member
If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.
-
Sep 22nd, 2003, 12:28 PM
#3
The nodelist wont retain the heirarchy above the nodelist. So there will be no root.
You can create a new xmldocument add your own root then loop through the nodelist and add all nodes as children though:
VB Code:
Dim nl As Xml.XmlNodeList
Dim newDoc As New Xml.XmlDocument
Dim root As Xml.XmlElement = newDoc.CreateElement("Root")
For Each nod As Xml.XmlNode In nl
root.AppendChild(nod)
Next
-
Sep 22nd, 2003, 12:37 PM
#4
Thread Starter
Lively Member
Yeah, but my problem is that it will not maintain the structure of the original xml document.
here is an example of my main xml.
Code:
<ROOT>
<VERSION MAJOR="3" REVISION="0">
<TAG NAME="Item1" VALID="true" DESCRIPTION="yada yada"/>
<TAG NAME="Item2" VALID="true" DESCRIPTION="yada yada"/>
<TAG NAME="Item3" VALID="true" DESCRIPTION="yada yada"/>
</VERSION>
<VERSION MAJOR="4" REVISION="0">
<TAG NAME="Item1" VALID="true" DESCRIPTION="yada yada"/>
<TAG NAME="Item2" VALID="true" DESCRIPTION="yada yada"/>
<TAG NAME="Item3" VALID="true" DESCRIPTION="yada yada"/>
</VERSION>
</ROOT>
now when I do a search for all Item 2's it works and returns both versions, so now I would like to recreate a xml file that has the same structure as the original.
Code:
<ROOT>
<VERSION MAJOR="3" REVISION="0">
<TAG NAME="Item2" VALID="true" DESCRIPTION="yada yada"/>
</VERSION>
<VERSION MAJOR="4" REVISION="0">
<TAG NAME="Item2" VALID="true" DESCRIPTION="yada yada"/>
</VERSION>
</ROOT>
after the search, when I try all logical methods of rebuilding a xml file both entries fall under one version node and not 2 seperate ones.
Keep in mind that this is a very small sample of my original xml, there are many nodes that fall under the item2 node its a huge tree structure.
If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.
-
Sep 22nd, 2003, 12:48 PM
#5
Thats because the SelectNodes doesn't care about structure and as I said the returned node does not maintain any heirarchy above it. So you are getting a list of TAG type nodes which is below the VERSION type so the structure is not kept. I think you either have to make seperate searches for each version node or you may be able to use the ParentNode property of the tag to add it first if its not already there.
-
Sep 22nd, 2003, 01:05 PM
#6
Thread Starter
Lively Member
Yeah, Its Silly though, you would think that they would give you the option to dump the results into a xmldocumentfragment or a nodelist. I know of the parentnode property and I have walked up the node to the root so now I'm just trying to put it all together with out dups, the function 626 of mine was almost there except there were duplicate root nodes and the versions nodes didn't keep there attributes. I'm almost there though, I built out a collection class that will hold each node returned with the structure break down. now I just have to merge all of these nodes into one colelction and then write it out.
Thanks for the info.
If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.
-
Sep 22nd, 2003, 02:09 PM
#7
Thread Starter
Lively Member
Ok. I Figured it out. It was a long drawn out process and there was no easy way to go about it...
If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|