Results 1 to 7 of 7

Thread: Dump a XML xpath search into a new xml.xmldocument. [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    94

    Question 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.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    94
    BUMP
    If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Dim nl As Xml.XmlNodeList
    2.         Dim newDoc As New Xml.XmlDocument
    3.         Dim root As Xml.XmlElement = newDoc.CreateElement("Root")
    4.         For Each nod As Xml.XmlNode In nl
    5.             root.AppendChild(nod)
    6.         Next

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    94
    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.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    94
    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.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    94
    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
  •  



Click Here to Expand Forum to Full Width