Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 343 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combining multiple xml documents into one large one with a batch file

#1
I have a directory of 86 xml files with the same columns and formatting that I need to combine into one large xml file. I am very inexperienced with batch files, and my first attempt was to simply append one file text onto the next using...

FOR %%i IN (directory\*.001) DO type %%i >> directory\combo_file.001

Unfortunately, this creates a Parse error when i try to open it in excel. I would imagine that this is because many fields and tags are repeated. Does anyone know how I might be able to achieve this? I only need to open this file in excel, so I would be open to converting files to CSV, if that was an option.

Any help is much appreciated, thanks!
Reply

#2
The problem is that XML has a single starting tag like: `<?xml version="1.0" encoding="UTF-8"?>` that would be repeated on the merged document. Also, if there's a root tag that contains all the others, merging you would include the root tag multiple times.

I think that it would be very hard (if possible) to do that in a batch shell, even using a powerful shell and commands like those in Linux/Unix (find, grep, etc).

I would use a simple program (say, VBA) to do that.

edit: I've found that in Excel you can import multiple xml files. You have to go to the Develop tab (show it if it's hidden). Then in the XML group, choose Import and select multiple XML files. That should work.
Reply

#3
<html xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<title>Book Title</title>
</head>
<body>
<xi:include href="chap1.xml"/>
<xi:include href="chap2.xml"/>
<xi:include href="chap3.xml"/>
</body>
</html>

When you process this one file with xslt it looks like all of the files combined.
Reply

#4
Here's a quick batch command that combines all the xml files in the current directory into a single file CombineXML.bat. It wraps all the XML files with a new root node ("<root>").

In your case, however, you may not want to introduce this new layer to the XML.
If all you're doing is viewing the XML in a single area (eg: in a web browser) then this works.

--CombineXML.bat--
@echo on
rem ==clean up==
erase %0.xml
rem ==add the root node==
echo ^<root^> > %0.txt
rem ==add all the xml files==
type *.xml >> %0.txt
rem ==close the root node==
echo ^<^/root^> >> %0.txt
rem ==rename to xml==
ren %0.txt %0.xml
Reply

#5
A very easy approach will be to do a simple copy:
>copy *.xml new.xml

The new.xml file created will have all the xml files merged together. You can create a BAT file with the same command
Reply

#6
When used with ANT, the <concat> task would be enough:

<echo file="header"><root>
</echo>

<echo file="footer"></root>
</echo>

<concat destfile="concatenated.xml">
<fileset file="header"/>

<fileset dir="....">
<include name="**/*.xml"/>
</fileset>

<fileset file="footer"/>
</concat>

This code produces a common <root> XML element and collects in it the contents of any .xml files it finds according to the file set. See:

*

[To see links please register here]

*

[To see links please register here]

*

[To see links please register here]

Reply

#7
And I have taken the sample from the above batch command to combine 100+ from one directory into one csv. and works very well.

--CombineXML.bat--
@echo on
rem ==clean up==
erase %0.xml
rem ==add the root node==
echo ^<root^> > %0.txt
rem ==add all the xml files==
type *.xml >> %0.txt
rem ==close the root node==
echo ^<^/root^> >> %0.txt
rem ==rename to csv==
ren %0.txt %0.csv
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through