batch xml generation
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Tue Oct 07, 2014 4:36 am
batch xml generation
Post by johnbucannan »
I have a requirement where I read data from database and form list of objects. The count of the objects can go upto 500000. I want to serialize these objects into an xml file but also make sure the size of the file doesn't surpass certain size for example 10 MB. As soon as the size reaches around 10 mb i start serializing into another file.I have to also make sure the xml formed is welformed. Apart from these objects there are few tags in the xml which will be common between files. Below is a sample of what I want:
File1
File2
Constant1, constant2, constant3 are common between files but elements inside data are the actual objects from DB
Need help to see how can i achieve this using java.Also, which xml generation way would be ideal?Tree based, stream or JAXB.
Thankyou
File1
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<batch>
<constant1>one</constant1>
<constant2>two</constant2>
<constant3>three</constant3>
<data>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
</data>
</batch>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<batch>
<constant1>one</constant1>
<constant2>two</constant2>
<constant3>three</constant3>
<data>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
<d>aaaaaaaaaaa</d>
</data>
</batch>
Need help to see how can i achieve this using java.Also, which xml generation way would be ideal?Tree based, stream or JAXB.
Thankyou
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: batch xml generation
Hi John,
This can probably be done in several ways, possibly avoiding building a DOM structure and serializing it if the XML is quite large (DOM takes in memory about 5-6 times more than the XML structure takes on disk).
You could for example use javax.xml.transform functionality like:
Regards,
Radu
This can probably be done in several ways, possibly avoiding building a DOM structure and serializing it if the XML is quite large (DOM takes in memory about 5-6 times more than the XML structure takes on disk).
You could for example use javax.xml.transform functionality like:
Code: Select all
TransformerFactory tf = TransformerFactory.newInstance();
final SAXTransformerFactory stf = (SAXTransformerFactory) tf;
TransformerHandler handler = stf.newTransformerHandler();
handler.setResult(new StreamResult(new File("test.xml")));
handler.startDocument();
handler.startElement("", "elemName", "elemName", null);
String text = "abc";
handler.characters(text.toCharArray(), 0, text.length());
handler.endElement("", "elemName", "elemName");
handler.endDocument();
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service