Merging two xml documents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gurudutta
    New Member
    • Jun 2007
    • 2

    #1

    Merging two xml documents

    Hi,

    This may be a simple problem which everyone has faced but I was looking for a best solution:-

    Assuming I have 2 Document objects:-

    One of them is :-

    <CONFIG>
    <TESTING>
    <TEST>
    <name>abc</name>
    </TEST>

    <TEST>
    <name> xyz </name>
    </TEST>
    </TESTING>
    </CONFIG>

    Now another document object is :-

    <City>
    <Name>Bangalore </Name>
    </City>

    Now progarmatically or using XSLT I want to obtain the result as follows:-


    <CONFIG>
    <TESTING>
    <TEST>
    <name>abc</name>
    </TEST>

    <TEST>
    <name> xyz </name>
    </TEST>
    </TESTING>
    <City>
    <Name>Bangalore </Name>
    </City>


    </CONFIG>

    Let me know the best method. All suggestions are welcome
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by gurudutta
    Hi,

    This may be a simple problem which everyone has faced but I was looking for a best solution:-

    Assuming I have 2 Document objects:-

    One of them is :-

    <CONFIG>
    <TESTING>
    <TEST>
    <name>abc</name>
    </TEST>

    <TEST>
    <name> xyz </name>
    </TEST>
    </TESTING>
    </CONFIG>

    Now another document object is :-

    <City>
    <Name>Bangalore </Name>
    </City>

    Now progarmatically or using XSLT I want to obtain the result as follows:-


    <CONFIG>
    <TESTING>
    <TEST>
    <name>abc</name>
    </TEST>

    <TEST>
    <name> xyz </name>
    </TEST>
    </TESTING>
    <City>
    <Name>Bangalore </Name>
    </City>


    </CONFIG>

    Let me know the best method. All suggestions are welcome
    I've copied this question to the XML forum.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by gurudutta
      Hi,

      This may be a simple problem which everyone has faced but I was looking for a best solution:-

      Assuming I have 2 Document objects:-

      One of them is :-

      <CONFIG>
      <TESTING>
      <TEST>
      <name>abc</name>
      </TEST>

      <TEST>
      <name> xyz </name>
      </TEST>
      </TESTING>
      </CONFIG>

      Now another document object is :-

      <City>
      <Name>Bangalore </Name>
      </City>

      Now progarmatically or using XSLT I want to obtain the result as follows:-


      <CONFIG>
      <TESTING>
      <TEST>
      <name>abc</name>
      </TEST>

      <TEST>
      <name> xyz </name>
      </TEST>
      </TESTING>
      <City>
      <Name>Bangalore </Name>
      </City>


      </CONFIG>

      Let me know the best method. All suggestions are welcome
      Use a SaxParser and pass it your own DefaultHandler (extend from that class).
      Your Defaulthandler simply writes everything it receives to that output until it
      receives the </CONFIG> tag, then it fires up another SaxParser which just
      writes everything to the output; finally your DefaultHandler writes the closing
      </CONFIG> tag.

      It's quite cheap that way (memory usage wise speaking that is).

      kind regards,

      Jos

      Comment

      Working...