PDA

View Full Version : I have like 50 XML files - what is the easiest way to combine them into one document?



spaceballl
February 15th, 2008, 12:24 AM
Hi all!

I have like 50 XML files. Is it possible to take them and combine them into one giant file? Each XML file has one root node and i want one document w/ all the nodes

shawnhcorey
February 15th, 2008, 01:38 AM
You can include then via ENTITY. Below foo.xml includes goo.xml. Note that goo.xml cannot contain a DOCTYPE.

You can create one master XML that contains all 50 XMLs.

foo.xml:

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE foo
[
<!ENTITY goo_xml SYSTEM "goo.xml">
]>

<foo>
&goo_xml;
</foo>


goo.xml:

<?xml version='1.0' encoding='UTF-8'?>

<goo>
Inside goo.xml
</goo>

Gen2ly
February 15th, 2008, 01:39 AM
or cat *.xml > onefile.xml

shawnhcorey
February 15th, 2008, 03:28 AM
or cat *.xml > onefile.xml

Only if you don't have to read it as an XML file.

Geekkit
February 15th, 2008, 04:11 AM
Only if you don't have to read it as an XML file.

Not true but only if ... the first document contains the open element tag and the last element contains the close element tag. :)

tgalati4
February 15th, 2008, 04:32 AM
You will have to edit the file if you cat the individual files. You could write a perl script or use an editing macro to delete the excess xml elements.

Or cat all the files together and try to load it and see what happens. Open your application in the command line so you can see the results. Post back with what you find.

popch
February 15th, 2008, 07:41 AM
Not true but only if ... the first document contains the open element tag and the last element contains the close element tag. :)

And if none of the files between contain any XML headers. Which would make them non-XML files.