Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:23:34+00:00 2026-06-06T00:23:34+00:00

I have two XmlDocuments that both have a namespace attribute specified. Both documents have

  • 0

I have two XmlDocuments that both have a namespace attribute specified. Both documents have the same structure, but contain different data. I can’t seem to get a specific node tree from one document added to the end of the same node tree in a second document. Here is an example of my two documents:

Document #1:

<?xml version="1.0"?>
<rootnode xmlns="http://www.mynamespace.com/Service/2012-06-18">
    <node0>
    </node0>
    <node1>
        <Item>
            <Id>1</Id>
            ....
        </Item>
        <Item>
            <Id>2</Id>
            ....
        </Item>
        <Item>
            <Id>3</Id>
            ....
        </Item>
    </node1>
</rootnode>

Document #2

<?xml version="1.0"?>
<rootnode xmlns="http://www.mynamespace.com/Service/2012-06-18">
    <node0>
    </node0>
    <node1>
        <Item>
            <Id>4</Id>
            ....
        </Item>
        <Item>
            <Id>5</Id>
            ....
        </Item>
        <Item>
            <Id>6</Id>
            ....
        </Item>
    </node1>
</rootnode>

What I’m wanting to accomplish:

<?xml version="1.0"?>
<rootnode xmlns="http://www.mynamespace.com/Service/2012-06-18">
    <node0>
    </node0>
    <node1>
        <Item>
            <Id>1</Id>
            ....
        </Item>
        <Item>
            <Id>2</Id>
            ....
        </Item>
        <Item>
            <Id>3</Id>
            ....
        </Item>
        <Item>
            <Id>4</Id>
            ....
        </Item>
        <Item>
            <Id>5</Id>
            ....
        </Item>
        <Item>
            <Id>6</Id>
            ....
        </Item>
    </node1>
</rootnode>

I’m trying to add all <Item> nodes from one document to the other while maintaining the structure of all other nodes. There are an arbitrary number of <Item> nodes in either of the documents. Each <Item> node has a deep nested number of nodes that describe the Item.

Dim dstdoc As XmlDocument = myobject1.XmlDocument
Dim srcdoc As XmlDocument = myobject2.XmlDocument

Dim nsmgr As New XmlNamespaceManager(New NameTable)
nsmgr.AddNamespace("ns", "http://www.mynamespace.com/Service/2012-06-18")

Dim xpath As String = "ns:rootnode/ns:node1//ns:Item"

Dim copiedNode As XmlNode = dstdoc.ImportNode( _
                            srcdoc.SelectSingleNode(xpath, nsmgr), True)
dstdoc.DocumentElement().AppendChild(copiedNode)

I certainly know this is wrong… I’ve tried several different approaches. This particular approach adds all <Item> nodes to the destination document, but it adds them to the very bottom of the document instead of after the last <Item>.

Could someone please show me how to add a specific node tree an XmlDocument to a specific position in another document? Again, there is a namespace involved and the <Item> nodes have nested nodes/elements under each one.

NOTE: The <Id> nodes have example data to show uniqueness only. I can never count on any kind of numbering. The order of each <Item> node is totally unimportant. I’m just assuming it will be easiest to add additional <Item> nodes after the last one in the destination document.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:23:37+00:00Added an answer on June 6, 2026 at 12:23 am

    You’re close. This line is incorrect:

    dstdoc.DocumentElement().AppendChild(copiedNode)
    

    That is explicitly saying that you want to append to the “document element” (meaning root element). If you want to append to a particular element in the destination document, you’ll first have to get a reference to that target element:

    Dim destElement As XmlNode = dstdoc.SelectSingleNode("ns:rootnode/ns:node1", nsmgr)
    For Each sourceNode in srcdoc.SelectNodes(xpath, nsmgr)
        Dim imported As XmlNode = dstdoc.ImportNode(sourceNode, True)
        destElement.AppendChild(imported)
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two inputs with the same date, but i want to separate the
I have a set of XML documents that all share the same schema. (They're
I have a website that needs to pull information from two diffferent XML data
I have two columns say Main and Sub . (they can be of same
I have two update panels on a page. And I want to update both
I have these two xml documents: XML 1: <outer> <foo> <foo-child name=fA special=true> content
I have two Hibernate data object. The first is a User (with unique id,
I have two web forms which are filled in by the user. They contain
What is the best/fastest way to merge two xml documents with ruby? I have
I am getting responses from two different web services in XML format. Both web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.