aspose file tools*
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
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: 1280

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
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
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?


Ping & DNS - my free Android networking tools app
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Multiple XML files from a Flat File To Individual xml files