Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

spaceballl

macrumors 68030
Original poster
Nov 2, 2003
2,938
362
San Francisco, CA
So i have like 50 xml files, each w/ a root node, and i just want one file, w/ all the nodes - what's the best way to do this? Thanks!
 
Could use some more info. Do the files have a common root node, which will remain to be the root node? Do you have some example XML of what these files look like?

You might be able to use something that appends the files (all text) then perhaps use regular expression search and replace to remove the unneeded parts. If this is something tht gets repeated a lot, this won't be a very good option.
 
No common root node.

Look at it this way...

file1.xml:
<Record1>random stuff here</Record1>​
file2.xml:
<Record2>random stuff here</Record2>​
file3.xml:
<Record3>random stuff here</Record3>​

What I want is...
onefile.xml:
<Record1>random stuff here</Record1>
<Record2>random stuff here</Record2>
<Record3>random stuff here</Record3>


I appreciate the help!
 
Well you can append files together pretty easy with Terminal.

cat *.xml > Master.xml

This will take all XML files in the current directory and catenate them together into a single file. Then to get rid of the XML declarations you can use,

grep -v "^<?xml" Master.xml > Master2.xml

You'll have to put the top XML declaration back in though.
 
Yeah, I'd recommend the cat command too. If you're not comfortable with grep you could always just open the whole thing up in a text editor afterwards and manually fix up whatever's left.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.