Page 1 of 1

Combining XML files

Posted: Mon May 04, 2015 1:52 pm
by _olq
How to cobine/merge XML files?
I have 2 or more files on the same structure in one folder, like this:

Code: Select all

<data-set>
	<record>
		</data1>
		</data2>
		</data…>
	</record>
</data-set>
I want to merge it together to one file, like this:

Code: Select all

<data-set>
	<record>
		</data1>
		</data2>
		</data…>
	</record>
	<record>
		</data1>
		</data2>
		</data…>
	</record>
</data-set>
Is it possible to do this e.g. send a folder containing several XML files and output file will be one XML file named like incoming folder?

Re: Combining XML files

Posted: Mon May 04, 2015 3:27 pm
by dkelly
Google "XSL merge" or write a simple Javascript

Re: Combining XML files

Posted: Mon May 04, 2015 4:21 pm
by _olq
yes I know :)
I use the 'XSLT transform' with the stylesheet, but...
How use it for many files in folder?

Re: Combining XML files

Posted: Mon May 04, 2015 5:46 pm
by dkelly
If necessary, rename the 2 XML files to make their names consistent. Then merge with a XSL like

Code: Select all

<?xml version="1.0" ?>
<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:copy>
            <xsl:copy-of select="document('file1.xml')" />
            <xsl:copy-of select="document('file2.xml')" />
        </xsl:copy>
    </xsl:template>
</xsl:transform>

Re: Combining XML files

Posted: Tue May 05, 2015 9:49 am
by _olq
For a various number of files I should use different scripts? There is no other way?
You wrote something about Javascript...

Re: Combining XML files

Posted: Mon May 11, 2015 11:34 pm
by dkelly
Apago would be able to write a custom Javascript to combine all XML files in a job folder. Contact us @ sales@apago.com for more information.

Re: Combining XML files

Posted: Tue May 12, 2015 10:27 am
by _olq
Thanks Dwight,

I make it in Perl. For me it was easier :)