This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Multiple XML files from a Flat File To Individual xml files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Multiple XML files from a Flat File To Individual xml files" Watch "Multiple XML files from a Flat File To Individual xml files" New topic
Author

Multiple XML files from a Flat File To Individual xml files

Pradeep Seth
Greenhorn

Joined: Jul 29, 2013
Posts: 1
Hi,

I am getting a flat file, ex: doc,pdf,txt, that file contains Multiple xml files.
Now I want to split those xmls in to individual xml files.

INPUT - My Flat test.doc, file having two xml.

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

OUTPUT - Now the Java program will split into two xml files ex : xmlfile1.xml & xmlfile2.xml

Please help me.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1294

You could simply read the original file line by line and and start a new XML file when you reach an XML preamble like <?xml ...>. This shouldn't be too hard.

Marco
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
DOC and PDF are not "flat files", they're structured binary formats that can not be read as easily as text files. How would they contain XML files?
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Multiple XML files from a Flat File To Individual xml files
 
It's not a secret anymore!