Combining XML files

Post Reply
_olq
Member
Posts: 36
Joined: Fri Aug 23, 2013 10:21 am
Location: Poland

Combining XML files

Post 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?
Aleksander
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Combining XML files

Post by dkelly »

Google "XSL merge" or write a simple Javascript
_olq
Member
Posts: 36
Joined: Fri Aug 23, 2013 10:21 am
Location: Poland

Re: Combining XML files

Post by _olq »

yes I know :)
I use the 'XSLT transform' with the stylesheet, but...
How use it for many files in folder?
Aleksander
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Combining XML files

Post 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>
_olq
Member
Posts: 36
Joined: Fri Aug 23, 2013 10:21 am
Location: Poland

Re: Combining XML files

Post by _olq »

For a various number of files I should use different scripts? There is no other way?
You wrote something about Javascript...
Aleksander
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Combining XML files

Post 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.
_olq
Member
Posts: 36
Joined: Fri Aug 23, 2013 10:21 am
Location: Poland

Re: Combining XML files

Post by _olq »

Thanks Dwight,

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