Merge XML

I have 2 Strings representing xml:
(The first String)
<bookshelf>
<book><title>1st Book</title>
<book><title>2nd Book</title>
<book><title>3rd Book</title>
<bookshelf>
(The second String)
<bookshelf>
<book><title>4th Book</title>
<book><title>5th Book</title>
<book><title>6th Book</title>
<bookshelf>
I would like to have the following String:
<bookshelf>
<book><title>1st Book</title>
<book><title>2nd Book</title>
<book><title>3rd Book</title>
<book><title>4th Book</title>
<book><title>5th Book</title>
<book><title>6th Book</title>
<bookshelf>
I read some example of merging file using xslt. But that involves using document() function. Since xml here is in memory I am not sure how to merge 2 xml documents.

But, how do I do that in xslt. xslt is just a template. I think I am missing a point here. I was referring to below example, only problem is that I don't have a file "file2.xml". My xml is in memory. I want to be able to use String that's in memory.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:variable name="file2" select="document('file2.xml')" />
<xsl:template match="/bookshelf">
<bookshelf>
<xsl:copy-of select="*" />
<xsl:copy-of select="$file2/bookshelf/*" />
</bookshelf>
</xsl:template>
</xsl:stylesheet>
Edited by: mohitanchlia on Jul 22, 2008 2:57 PM

Similar Messages

  • Merging XML and XDP files

    Hello!
    I must build this POC for a client and the idea is merge XML and XPD files to feed a LiveCycle Output process and create PDF files.
    I've built the XDP files and the XML to start things, now I need to figure out how to create the process to merge them in Workbench.
    Is there any tutorial to help me with this task?
    Thank you for any ideas!
    Marcos

    Thank you guys for helping a beginner in trouble.
    I hope I will soon be able to help others here and help the comnunity.
    Right now, I've so much to learn!
    Thank you!
    Marcos, Brazil

  • Capture data in 1D barcode upon merging XML with XDP?

    Hi,
    The scenario is:
    Forms Server 7.2.2 is being used for merging XML data with an XDP file to render a PDF (displaying a pre-filled form to user).
    On the XDP, there is a 1D Barcode and few fields are mapped to this barcode (the barcode is intended to capture form identification information).
    Upon merging, the barcode should capture the data of those fields (data is being fetched from a db and fed as XML to Forms server). This is required as the pre-filled form will be printed and then mailed to another location, where the barcode will be read using a decoder to capture form indentification.
    Will the 1D barcode captures data from those fields, after merging XML with XDP?
    The form is NOT Reader Extended. Is Reader Extending a necessity for enabling 1D barcode to capture data?
    Is this also applicable for 2D barcodes?
    Thanks a lot for your help! :)

    Thank you Hodmi,
    I had forgotten to define the Record name parameter in the PDF Output Options.
    As the XML structure changed, not upating this parameter was preventing the process from working.
    Now it is working just fine. Thank you!
    Marcos

  • Need to merge xml o/p from different sources to generate BIP Report from OA page

    Hi,
    Currently in our product Quoting , we are using many VO queries to generate the Report
    Now we have created one data template file to combine all VO queries to generate xml o/p
    The problem we are facing is that we didn't added Contracts VO query in our DT file so we need to merge
    xml o/p coming from DT file and Contracts VO and pass to Process Template XDO api to generate the report
    Please tell how to merge the xml o/p in OAF ?

    Thanks Shridhar for reply ,  you provided code for xml coming from two VO
    but I am having scenario where getting one xml o/p from data template file and seconf xml o/p getting from contracts api as -
    ByteArrayOutputStream l_docXML = new ByteArrayOutputStream(1024);
    // Here getting xml o/p from DT file
    l_docXML = (ByteArrayOutputStream)this.getDataTemplateXML(transaction,"ASO","ASOPD",parameters1,null);
    // Here getting xml o/p from contacts api
    ContractTermsXMLGenerator.writeXML(PrintQuote,
                        (OutputStream) l_conXML,
       true,
       documentType,
       new Number(params[8]),
       new Number("0"));
    // code to merge two xml into one xml m_docXML
    try{
                 if (l_conXML.size() > 0)
                      DOMParser dp = new DOMParser();
                      l_docIP = new ByteArrayInputStream(l_docXML.toByteArray()); 
                      dp.parse(l_docIP);
                      XMLDocument xDoc = dp.getDocument();
                      l_conIP = new ByteArrayInputStream(l_conXML.toByteArray());
                      dp.parse(l_conIP);
       XMLDocument cDoc = dp.getDocument();
       Node cNode = cDoc.getDocumentElement();
                      if (cNode != null)
                           Node xDocConNode = xDoc.adoptNode(cNode);
                           Node conData = xDoc.createElement("CONTRACT_DATA");
                           conData.appendChild(xDocConNode);
                           xDoc.getDocumentElement().appendChild(conData);
                         xDoc.print(m_docXML);
                         writeLog("GenerateCLMDoc::XMLMerge Complete");
               catch(Exception e)
           writeLog("GenerateCLMDoc:: Doc contract XML Merge - " + e.getMessage());
                      throw e;
        finally{
                        l_docIP.close();
                        l_conIP.close();
    Please check if it is correct code , do I need to change it with code provided by you
    can we chat over any messenger ?
    once again thanks for your reply

  • Merge xml source files; 1:n relationship

    Hi!
    All samples I have checked are based on 1:1 relationship
    between master and detail data set.
    For example:
    Exactly one xml file will be loaded depending on which
    element of the master xml file is selected.
    http://labs.adobe.com/technologies/spry/samples/data_region/DataSetMasterDetailSample.html
    But what about 1:n relationships? What if the master xml
    returns more than one depending xml file?
    Two scenarios are imaginable:
    1. Collect all detail xml data by looping through all data
    rows and create a dataset on the fly with all relevant data.
    (Please note my last posting "Observer event fires two times") That
    could be a new merge function ;-)
    2. Implementation of a new XMLDataSet constructor that allows
    an array with one or more path to detail xml file(s).
    What do you think about it? Or is there another way to handle
    1:n relationships?
    Regards
    libelle2000

    Hi !
    On Srpy 1.4 version the 1:n relation is not supported, but we
    have two new solutions for this already posted on preview section.
    http://labs.adobe.com/technologies/spry/preview/samples/data_region/NestedXMLDataSample.ht ml
    Instead of creating one master xml file that points to other
    details xml files, you can have a single xml and create there the
    1:n relation there. In this way your request is solved using a
    single xml file.
    Please follow the link I gave you above and see the examples
    from there.
    Diana

  • Merging XML Data to make many documents

    Hello,
    Here's where I am at:
    I've used LifeCycle Designer to create a PDF with all the forms named. I have XML data for all my companys. The XML data merges into the document, and fills in the form perfectly.
    However, I'm looking to take this one step further, and automate the process. Meaning, Putting all the company data in one file, and importing the data to make PDF forms for each company.
    Similar to a mail merge. --Lots of different Companys, Fill in thier each individual page.
    What are the steps to do this?
    Thanks!
    --Jeff

    Yes.
    You can do one of the following:
    a) Build a custom application using the LiveCycle Forms api.
    b) Use the RenderForm QPAC within a workflow to convert the XML to a PDF.
    The RenderForm QPAC is a little obscure to use - read the documentation VERY carefully, and be very careful about the values you enter, otherwise it won't work. It does work perfectly if you get all the values right. In my experience, you do need to enter a username and password, even though these are not noted as mandatory fields.
    Howard
    http://www.avoka.com

  • How to merge XML-Data of two variables?

    Hi all,
    I have to combine information coming from 2 different sources (1st delivered by client input, 2nd delivered by ftp-adapter) for passing it to another service.
    So there are different namespaces for the three describing xsd's (2 in, 1 out). As every structure is composed of several elements, I don't want to copy them one by one . But when copying a whole node with child elements, the target structure yields empty nodes, because the target child elements obtain the source namespace!
    Using 2 XSLT's works well for each input, but in combination, the last translate deletes the information of the first one.
    So, the only way to merge the data I figured out by now, is to use a XSLT for each input transforming into 2 separate Variables belonging to the same namespace and then copying the complete nodes of the two variables into the target (which of course belongs to this namespace as well).
    Although there is an inconsistent indexing of the namespaces (see example), happily all data can be accessed.
      <CommonData>
        <CommonData xmlns="http://TargetNamespace.com/CommonData">
          <FileInfo xmlns="http://TargetNamespace.com/CommonData">
            <Name>testfile2.txt</Name>
            <Size/>
            <DateReceived>2009-02-10T17:15:46+01:00</DateReceived>
          </FileInfo>
          <FileData xmlns:ns0="http://TargetNamespace.com/CommonData">
            <ns0:KOPF>
              <ns0:Id>1</ns0:Id>
              <ns0:Value>1</ns0:Value>
              <ns0:Text>Hier könnten Ihre Daten stehen -</ns0:Text>
            </ns0:KOPF>
            <ns0:POSI>
              <ns0:Id>1</ns0:Id>
              <ns0:Position>1</ns0:Position>
              <ns0:Value>1</ns0:Value>
              <ns0:Text>eins ----</ns0:Text>
            </ns0:POSI>
            <ns0:POSI>
              <ns0:Id>2</ns0:Id>
              <ns0:Position>2</ns0:Position>
              <ns0:Value>2</ns0:Value>
              <ns0:Text>zwei ----</ns0:Text>
            </ns0:POSI>
          </FileData>
        </CommonData>
      </CommonData>Now for the question:
    Is this really the only way to merge variables? As it took 4 operations to achieve this, it seems to be too complicated, and therefore too inperformant to me.
    BTW: In real life there would be up to 9999 positions whith much more payload to be processed ;-)
    Any comments appreciated,
    cheers, Marco
    Edited by: MarcoSfromGER on 11.02.2009 08:43

    Well, if you only want to change namespace (no other changes) I would use a single generic XSL that changes the namespace for any XML document into a given target namespace, keeping the rest. That will require two transformation calls, but only one XSL. I'm afraid I don't have an example available, but if you google perhaps you can find it, I have seen it somewhere.
    Normally when you have different namespaces the contents differ as well, though, and what you really want is a merge function. There is a way to pass two documents into a single XSL and that is to use parameters. You pass one source document the normal way and assign the other converted to a string to a paramter. You must use an assign with processXSLT in BPEL, not a transform activity. The processXSLT really takes three arguments and the third contains the parameters. Now to the difficulty - in the transformation you need to change the string into a nodeset (an XML document). In the current XPath version used by the platform there is no nodeSet function, but it is possible to write one in Java. If you have it you can select from both documents while building the third. I don't have an example handy and yes it is a bit messy as well, but much of the work only has to be done once and can be reused in other processes.

  • How to merge XML-Data of two variables of different namespace?

    Hi all,
    I am facing a problem manipulating XML data in a BPEL process. As I didn't get any response on my question in the BPEL forum, I decided to post it again in this forum. I am not very familiar with using XML up to this moment, so please don't blame me if this turns out to be a stupid question.
    I have to combine information coming from 2 different sources (1st delivered by BPEL-client input "FileInfo", 2nd delivered by a ftp-adapter "FileData") for passing it to another service.
    So there are 3 XSDs (2 in, 1 out), each with a different namespace. As every structure is composed of several elements, I don't want to copy them one by one. But when copying a whole node including child elements, the target structure yields empty nodes, because the target child elements maintain the source namespace!
    Using 2 XSLT's works well for each input, but in combination, the last transformation deletes the information of the first one.
    So, the only way to merge the data I figured out by now, is to use a XSLT for each input, transforming it into 2 separate Variables belonging to the same namespace and then copying the complete nodes of the two variables into the target (which of course belongs to the common namespace as well).
    Although there is an inconsistent indexing of the namespaces (see example), happily all data can be accessed.
      <CommonData>
        <CommonData xmlns="http://TargetNamespace.com/CommonData">
          <FileInfo xmlns="http://TargetNamespace.com/CommonData">
            <Name>testfile2.txt</Name>
            <Size/>
            <DateReceived>2009-02-10T17:15:46+01:00</DateReceived>
          </FileInfo>
          <FileData xmlns:ns0="http://TargetNamespace.com/CommonData">
            <ns0:KOPF>
              <ns0:Id>1</ns0:Id>
              <ns0:Value>1</ns0:Value>
              <ns0:Text>Hier könnten Ihre Daten stehen -</ns0:Text>
            </ns0:KOPF>
            <ns0:POSI>
              <ns0:Id>1</ns0:Id>
              <ns0:Position>1</ns0:Position>
              <ns0:Value>1</ns0:Value>
              <ns0:Text>eins ----</ns0:Text>
            </ns0:POSI>
            <ns0:POSI>
              <ns0:Id>2</ns0:Id>
              <ns0:Position>2</ns0:Position>
              <ns0:Value>2</ns0:Value>
              <ns0:Text>zwei ----</ns0:Text>
            </ns0:POSI>
          </FileData>
        </CommonData>
      </CommonData>Now for the question:
    Is this really the only way to merge variables? As it took 4 operations to achieve this, it seems to be too complicated, and therefore too inperformant to me.
    BTW: In real life there would be up to 9999 positions with much more payload (in total up to several MBs) to be processed!
    Having full control of the namespaces in this case, I could think of using one namespace for all XSDs too. But would this be a better solution? Is there a golden rule on using namespaces relating to design issues?
    Any comments appreciated,
    cheers, Marco

    Well, if you only want to change namespace (no other changes) I would use a single generic XSL that changes the namespace for any XML document into a given target namespace, keeping the rest. That will require two transformation calls, but only one XSL. I'm afraid I don't have an example available, but if you google perhaps you can find it, I have seen it somewhere.
    Normally when you have different namespaces the contents differ as well, though, and what you really want is a merge function. There is a way to pass two documents into a single XSL and that is to use parameters. You pass one source document the normal way and assign the other converted to a string to a paramter. You must use an assign with processXSLT in BPEL, not a transform activity. The processXSLT really takes three arguments and the third contains the parameters. Now to the difficulty - in the transformation you need to change the string into a nodeset (an XML document). In the current XPath version used by the platform there is no nodeSet function, but it is possible to write one in Java. If you have it you can select from both documents while building the third. I don't have an example handy and yes it is a bit messy as well, but much of the work only has to be done once and can be reused in other processes.

  • Merging XML documents using DOM

    I have 300 XML documents to merge. They contain structures such as:
    1.xml=
    <MIM>
    <MIM-ENTRY>
    <MIM-NUMBER>123456
    </MIM-NUMBER>
    </MIM-ENTRY>
    </MIM>
    2.xml =
    <Mim>
    -<Mim-entry>
    <Mim-title>*604176 SUPPRESSOR OF CYTOKINE SIGNALING 3</Mim-title>
    </Mim-entry>
    </Mim>
    3.xml=
    <Mim>
    <Mim-entry>
    <Mim-alternative_titles_and_symbols>
    <Mim-alternative_titles_and_symbols-alt>SOCS3</Mim-alternative_titles_and_symbols-alt>
    </Mim-alternative_titles_and_symbols>
    </Mim-entry>
    </Mim>
    all the XML files have this sort of structure.
    Essentailly, I need to merge them (using the above as an example) to get:
    <MIM>
    <MIM-ENTRY>
    <MIM-NUMBER>123456</MIM-NUMBER>
    <Mim-title>*604176 SUPPRESSOR OF CYTOKINE SIGNALING 3</Mim-title>
    <Mim-alternative_titles_and_symbols>
    <Mim-alternative_titles_and_symbols-alt>SOCS3</Mim-alternative_titles_and_symbols-alt>
    </Mim-alternative_titles_and_symbols>
    </Mim-entry>
    </MIM>
    I have all the trees stored in a Vector as DOM objects.
    Anyone have any ideas how to merge these documents as stated?
    Any help would be most appriciated

    Ah, think im begining to get you. And if I am undertstanding you correctly it might not solve my problem.
    Ok, so the files exist as follows:
    file1.xml
    <MIN>
    <MIM-1>
    <MIM-2>something
    </MIM-2>
    </MIM-1>
    </MIM>
    file2.xml
    <MIN>
    <MIM-1>
    <MIM-3>somethingelse
    </MIM-3>
    </MIM-1>
    </MIM>
    merged to give:
    <MIN>
    <MIM-1>
    <MIM-2>something
    </MIM-2>
    <MIM-3>somethingelse
    </MIM-3>
    </MIM-1>
    </MIM>
    SO....
    I have to bring out the nodes <MIM-2> from file1.xml and import them. in file2 appendChild will be applied to <MIM1> using those nodes.
    This is really not what i was looking for.
    I wanted to throw everything together. Reason? I will be merging over 300 xml documents all of which will be inserting elements at different depths. This method you describe (i think) will need the specific nodes to be extracted from each and every DOM structure. This might not be possible as the XML stuctures will change depend on the program circumstances.
    I would like to just to put all the DOMS together and Tags of the same name will simply merge. to give the output above.
    Or does method you descibed this actually do this?
    I apologise for my stupidity in advance.
    litkid

  • Merging XML Files After Debatching - 10.1.3.4

    I have a large fixed-width file which I am debatching and transforming to XML files:
    bigfile.txt (~52MB) -> file_%SEQ%.xml (~4MB each)
    resulting in:
    file_2001.xml (~4MB)
    file_2002.xml (~4MB)
    file_2003.xml (~4MB)
    file_2004.xml (~4MB)
    I would like to merge these resulting XML files back into one XML file:
    bigfile.xml (~52MB)
    I know the [Append="true"] attribute in the file adapter used to write the file won't "work" with XML files. I've tested this anyway and received "out of memory" errors while appending. This removes post-processing options.
    I'm new to BPEL and feel that I must be missing something simple. Any advice would be appreciated.
    Thanks in advance,
    Rob

    Hi Rob,
    You can create a temp variable of xsd type of bigfile.xml, read all below files one by one and within assign activity use append operation to append all xml files, when all read is complete, dispatch this message to file adapter to write file.
    file_2001.xml (~4MB)
    file_2002.xml (~4MB)
    file_2003.xml (~4MB)
    file_2004.xml (~4MB)
    Here, there is a possibility of out of memory error.
    Please try it,
    Regards

  • Merging XML files

    Hi All,
    I want to merge two XML files using XSL under Apache's Xalan.
    Or If there is any way to merge two XMI documents (XML For Metadata Ineterchange) then it is well.

    sure, use the document() function in XSL to call the content of another XML.
    <xsl:apply-templates select="document('http://myfile1.xml')"/>
    <xsl:apply-templates select="document('http://myfile2.xml')"/>

  • Merging xml files element by lement

    Hi, I have two xml files of dept and emp tables. I want to merg these two xml files in such a way that the output should be grouped by deptnos.
    i.e., under dept deptno 10 child node, i should get all emp child nodes who have deptno 10. How can I do this using DBMS_XMLDOM. Please help. Thank you.
    dept xml -
    <?xml version="1.0"?>
    <DEPT_SET>
    <DEPT>
    <DEPTNO>10</DEPTNO>
    <DNAME>ACCOUNTING</DNAME>
    <LOC>NEW YORK</LOC>
    </DEPT>
    <DEPT>
    <DEPTNO>20</DEPTNO>
    <DNAME>RESEARCH</DNAME>
    <LOC>DALLAS</LOC>
    </DEPT>
    <DEPT>
    <DEPTNO>30</DEPTNO>
    <DNAME>SALES</DNAME>
    <LOC>CHICAGO</LOC>
    </DEPT>
    <DEPT>
    <DEPTNO>40</DEPTNO>
    <DNAME>OPERATIONS</DNAME>
    <LOC>BOSTON</LOC>
    </DEPT>
    </DEPT_SET>
    emp xml -
    <?xml version="1.0"?>
    <EMP_SET>
    <EMP>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>17-DEC-80</HIREDATE>
    <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7499</EMPNO>
    <ENAME>ALLEN</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>20-FEB-81</HIREDATE>
    <SAL>1600</SAL>
    <COMM>300</COMM>
    <DEPTNO>30</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7521</EMPNO>
    <ENAME>WARD</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>22-FEB-81</HIREDATE>
    <SAL>1250</SAL>
    <COMM>500</COMM>
    <DEPTNO>30</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7566</EMPNO>
    <ENAME>JONES</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>02-APR-81</HIREDATE>
    <SAL>2975</SAL>
    <DEPTNO>20</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7654</EMPNO>
    <ENAME>MARTIN</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>28-SEP-81</HIREDATE>
    <SAL>1250</SAL>
    <COMM>1400</COMM>
    <DEPTNO>30</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7698</EMPNO>
    <ENAME>BLAKE</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>01-MAY-81</HIREDATE>
    <SAL>2850</SAL>
    <DEPTNO>30</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7782</EMPNO>
    <ENAME>CLARK</ENAME>
    <JOB>MANAGER</JOB>
    <MGR>7839</MGR>
    <HIREDATE>09-JUN-81</HIREDATE>
    <SAL>2450</SAL>
    <DEPTNO>10</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7788</EMPNO>
    <ENAME>SCOTT</ENAME>
    <JOB>ANALYST</JOB>
    <MGR>7566</MGR>
    <HIREDATE>09-DEC-82</HIREDATE>
    <SAL>3000</SAL>
    <DEPTNO>20</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7839</EMPNO>
    <ENAME>KING</ENAME>
    <JOB>PRESIDENT</JOB>
    <HIREDATE>17-NOV-81</HIREDATE>
    <SAL>5000</SAL>
    <DEPTNO>10</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7844</EMPNO>
    <ENAME>TURNER</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>08-SEP-81</HIREDATE>
    <SAL>1500</SAL>
    <COMM>0</COMM>
    <DEPTNO>30</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7876</EMPNO>
    <ENAME>ADAMS</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7788</MGR>
    <HIREDATE>12-JAN-83</HIREDATE>
    <SAL>1100</SAL>
    <DEPTNO>20</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7900</EMPNO>
    <ENAME>JAMES</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7698</MGR>
    <HIREDATE>03-DEC-81</HIREDATE>
    <SAL>950</SAL>
    <DEPTNO>30</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7902</EMPNO>
    <ENAME>FORD</ENAME>
    <JOB>ANALYST</JOB>
    <MGR>7566</MGR>
    <HIREDATE>03-DEC-81</HIREDATE>
    <SAL>3000</SAL>
    <DEPTNO>20</DEPTNO>
    </EMP>
    <EMP>
    <EMPNO>7934</EMPNO>
    <ENAME>MILLER</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7782</MGR>
    <HIREDATE>23-JAN-82</HIREDATE>
    <SAL>1300</SAL>
    <DEPTNO>10</DEPTNO>
    </EMP>
    </EMP_SET>
    Required output is -
    <?xml version="1.0"?>
    <DEPT_SET>
    <DEPT>
    <DEPTNO>10</DEPTNO>
    <DNAME>ACCOUNTING</DNAME>
    <LOC>NEW YORK</LOC>
    </DEPT>
    <DEPT>
    <DEPTNO>20</DEPTNO>
    <DNAME>RESEARCH</DNAME>
    <LOC>DALLAS</LOC>
    </DEPT>
    <EMP>
    <EMPNO>7369</EMPNO>
    <ENAME>SMITH</ENAME>
    <JOB>CLERK</JOB>
    <MGR>7902</MGR>
    <HIREDATE>17-DEC-80</HIREDATE>
    <SAL>800</SAL>
    <DEPTNO>20</DEPTNO>
    </EMP>
    <DEPT>
    <DEPTNO>30</DEPTNO>
    <DNAME>SALES</DNAME>
    <LOC>CHICAGO</LOC>
    </DEPT>
    <DEPT>
    <DEPTNO>40</DEPTNO>
    <DNAME>OPERATIONS</DNAME>
    <LOC>BOSTON</LOC>
    </DEPT>
    </DEPT_SET>

    Well, if you are building the dept and emp XML files yourself, then the easiest solution is to use one SQL/XML (XMLElement, XMLForest, XMLAgg) statement to build the required XML instead of building two pieces and trying to merge.
    If you can't go that option, then you can use importNode and appendChild to insert your selected nodes into the correct spot in the main XML.
    As a starter, here is a snippet of code that takes a single node from a temp DOMDocument and inserts it into the master DOMDocument at a certain location.
        l_inq_nodelist := dbms_xmldom.getelementsbytagname(l_temp_domdoc,
                                                           'theDesiredNode');
        l_inq_nl_len := xmldom.getlength(l_inq_nodelist);
        IF l_inq_nl_len > 0 THEN
           -- Take the node above and adopt it into the response document
           l_temp2_nd := dbms_xmldom.importNode(o_response_doc,
                                                dbms_xmldom.item(l_inq_nodelist, 0),
                                                TRUE);
           -- Put the node in the correct position in the response document                                          
           l_temp2_nd := xdb.dbms_xmldom.appendChild(l_rsp_msg_nd, l_temp2_nd);
        END IF;I know your situation is slightly different as you need to take multiple nodes but once you can select out your nodes from the emp XML, you can use the above to insert into the dept XML. I would provide more samples but it has been a while since I've read XML via DOMDocument as I use XMLType when reading XML. Feel free to post what you have if you get stuck.

  • Using PLSQL to merge XML docs

    Hi All, I am looking for a general approach to how I can merge data in one xml file into another xml file that has the schema imbeded in it. I am sure XSLT is in here somewhere but just a bit unfamiliar with the approach.
    Here is what we are doing. We have a MS Word doc, in WordML. I has an attached schema and the document has been marked up with this schema. We extract data from the database in this schema format and now want to merge the two to produce a word document.
    thanks
    Don

    When I worked with populating MS Word Mail merge fields from a database it was quite gnarly (the documents contained repeating groups and we ended up with lots of macros driving embedded SQL) but the basic principle was:
    (1) A template with placeholders (the mail merge fields)
    (2) A data set
    This seems to be a perfectly simple model and one that's ideal for XML too.
    Your problem is that you have
    (1) An XML document with a structure you want but not the data
    (2) A different XML document with data you want but not in the right structure
    Whilst this does look a bit like a mail merge model you must admit the differences are more compelling than the similarities.
    I guess I am asking why you just don't hollow out the Word document and populate it directly from the database. That seems to me the simplest solution.
    If you have good reasons for doing it the way you say then I suggest a database forum is the wrong place to be asking for guidance. You really ought to be asking in a Java/C#/XSLT forum. I have no expereince with WordML but this post suggests what seems to me a sound approach: creating XML fragments and integrating them into the body of a WordML doc.
    Cheers, APC

  • Merging XML Doc's

    Hi
    I have a servlet that builds up two different connections. The 2 databases holds the same type of data, ie the select statement is the same, it just brings back different time period values. I need to combine these two XML docs into one XML document, massage it a bit, apply style sheet and send to browser.
    I have now succeeded in doing the XML doc , massage and sending. However, I'am battling to combine the two xml doc's into one. any help appreciated.
    Tks
    Andre
    Here is the Servler code:
    String query = queryBuff.toString();
    OracleXMLQuery q1 = new OracleXMLQuery(conn1, query);
    q1.useLowerCaseTagNames();
    q1.setRowsetTag("CARDSLOADED");
    q1.setRowTag("CARDREC");
    XMLDocument xmldoc1 = (XMLDocument)q1.getXMLDOM();
    // now 2nd
    OracleXMLQuery q2 = new OracleXMLQuery(conn2, query);
    q2.useLowerCaseTagNames();
    q2.setRowsetTag("CARDSLOADED");
    q2.setRowTag("CARDREC");
    XMLDocument xmldoc2 = (XMLDocument)q2.getXMLDOM();
    So I need to combine xmldoc1 and xmldoc2. The stylesheet will do the Order by for me.
    Tks

    Hi - got it going ...tks
    You need to step down into the XMLDOC to get the nodes and not start at the beginning
    Sameple code -
    try
    String query = queryBuff.toString();
    System.out.println("query is >"+query);
    OracleXMLQuery q = new OracleXMLQuery(conn2, query);
    q.useLowerCaseTagNames();
    q.setRowsetTag("CARDSLOADED");
    q.setRowTag("CARDREC");
    xmldoc2 = (XMLDocument)q.getXMLDOM();
    // num_rows = q.getNumRowsProcessed();
    } //end try
    catch (Exception exc)
    out.println(exc.toString());
    // Now attemt to merge the two xml docs
    try
    NodeList list = xmldoc1.getElementsByTagName("CARDSLOADED");
    Node root = list.item(0);
    NodeList list1 = xmldoc2.getElementsByTagName("CARDREC");
    // now loop from pos 0 to end and add each node
    int noOfRecs = list1.getLength();
    for (int i=1; i <= noOfRecs -1; i++)
    Node child=list1.item(i);
    Node copy = xmldoc1.importNode(child, true);
    root.appendChild(copy);
    catch (Exception exc)
    System.out.println("Error merging "+exc.toString());

  • Merging XML

    I am using importNode() to add some elements in doc1.xml to doc2.xml.
    after i use importNode the lements are not appended. I am getting the doc2.xml as is.
    I should put this beforer a tag called <aaa>
    So i am using insertBefore(childnode,refnode)
    How do i get this refNode() ? it is giving me nullpointer even if there is this node existing......
    Any suggesstions.
    Thanks in advance

    There is no problem adding multiple <aaa> elements. But, an object can only be in a Document in one place.
    So, if you code
    for( int i=0; i< nl.length(); i++ )
    impNode = doc.
    Node impNode;  // creates a null Node
    for(int i=0;i<aaaTag2.getLength();i++){
        impNode=document1.importNode(aaaTag2.item(i),true);
       Node n1=document1.insertBefore(impNode,refNode);
    }You are doing the following:
    1) create a Node object called impNode.
    2) assign impNode a new value -- the value of the first <aaa> element from the second document, with the document ownership fixed.
    3) inserting this new <aaa> element before the exisitng first <aaa> tag of document 1.
    4) assigning a new value to impNode **** This is the same object, but with a new value.
    5) when you try to insert it as the first of three <aaa> tags, the code realizes that this same object is already the first of the two <aaa> tags, so it deletes the copy already added to document 1, and then adds it back, but with the second set of data in it.
    etc.
    Try doing a
    System.out.println( "node count in document 1" +
    document1.getElementsByTagName( "aaa").length() );
    inside the for loop.
    Then try changing the code to read:
    for(int i=0;i<aaaTag2.getLength();i++){
       Node  impNode=document1.importNode(aaaTag2.item(i),true);
       Node n1=document1.insertBefore(impNode,refNode);
    }That should work.
    I don't understand how you could not get one additional element added.
    You might try to use a DocumentFragment. When you insert a DocumentFragment, it inserts all of the children of the DocumentFragment, and you can reuse the DocumentFragment object.
    Dave Patterson

Maybe you are looking for