cancel
Showing results for 
Search instead for 
Did you mean: 

How to merge two XML files into a single one?

0 Kudos

I have two separate SQL queries and I have to modify both outputs with XSLT transformations. After that I will have 2 .xml files that I have to join into a single .xml file. Is it possible to do that?

1st

<rowsets>

  <rowset>

    <head>

      <column align="center" width="70">col1</column>

      <column align="center" width="80">col2</column>

      <column align="center" width="90">col3</column>

    </head>

  </rowset>

</rowsets>

2nd

<rowsets>

  <rowset>

    <head/>

    <row id="1">

      <cell>1</cell>

      <cell>2</cell>

      <cell>3</cell>

    </row>

    <row id="2">

      <cell>11</cell>

      <cell>22</cell>

      <cell>33</cell>

    </row>

    <row id="3">

      <cell>a</cell>

      <cell>b</cell>

      <cell>c</cell>

    </row>

  </rowset>

</rowsets>

result

<rowsets>

  <rowset>

    <head>

      <column align="center" width="70">col1</column>

      <column align="center" width="80">col2</column>

      <column align="center" width="90">col3</column>

    </head>

    <row id="1">

      <cell>1</cell>

      <cell>2</cell>

      <cell>3</cell>

    </row>

    <row id="2">

      <cell>11</cell>

      <cell>22</cell>

      <cell>33</cell>

    </row>

    <row id="3">

      <cell>a</cell>

      <cell>b</cell>

      <cell>c</cell>

    </row>

  </rowset>

</rowsets>

I do not insist that this should be the fix format for input .xml files. The only thing that "columns" and "rows" will come from two separate sources.

Thx

Accepted Solutions (1)

Accepted Solutions (1)

former_member185280
Active Contributor
0 Kudos

I was able to do it this way:

Regards,
Christian

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

1. You can use Union action block to join to XML

2. In the configure link tab you can use any of the below link type to append/merge/join two xml. Using this more then 1 XML can be merged that too at desired location

swaroop_anasane
Active Contributor
0 Kudos

Hi Mahesh,

It's not about block by block merging. He wants to convert rows into columns and assign rowset accordingly.

Regards,

Swaroop

swaroop_anasane
Active Contributor
0 Kudos

Hi Tibor,

Below is the output i got.

[Tracer_2]<?xml version="1.0" encoding="UTF-8"?><Rowsets DateCreated="2015-04-05T23:22:05" EndDate="2015-04-03T11:10:27" StartDate="2015-04-03T11:10:27" Version="14.0 SP5 Patch 11 (Aug 27, 2014)">

    <Rowset>

        <Columns>

            <Column Description="" MaxRange="100" MinRange="0" Name="col1" SQLDataType="1" SourceColumn="col1"/>

            <Column Description="" MaxRange="100" MinRange="0" Name="col2" SQLDataType="1" SourceColumn="col2"/>

            <Column Description="" MaxRange="100" MinRange="0" Name="col3" SQLDataType="1" SourceColumn="col3"/>

        </Columns>

        <Row>

            <col1>1</col1>

            <col2>2</col2>

            <col3>3</col3>

        </Row>

        <Row>

            <col1>11</col1>

            <col2>22</col2>

            <col3>33</col3>

        </Row>

        <Row>

            <col1>a</col1>

            <col2>b</col2>

            <col3>c</col3>

        </Row>

    </Rowset>

</Rowsets>

Please find the image below to achieve this. Please note, I have used local variables to assign input xmls and repeat through it. Repeater_0 for Headers and Repeater_1 for body.

Kindly ignore Doc_0 here, it's for another purpose. Document_1 is what we are focussing on.

Please note, you would not be able to see columns as those are dynamically created. Still you can map it as shown above.

Hope this helps.

Best Regards,

Swaroop

swaroop_anasane
Active Contributor
0 Kudos

Hi Tibor,

Union would not help you here. You will have to create an XML doc and append columns and rows to it using a repeater.

Best Regards,
Swaroop

Former Member
0 Kudos

Hi Tibor,

Try using the MII Union action block . See the documentation here:

https://help.sap.com/saphelp_mii122sp01/helpdata/en/44/76cd6333003abee10000000a155369/content.htm

Regards,

Anushree

0 Kudos

Hi,

that documentation is poor. There's no example what should be the XML-format. I tried it with my .xml files and it is not working, it doesn't return the "mixture" of the .xml files.

Former Member
0 Kudos

Hi,

Could you mention what exactly is returned.

Regards,
Anushree