0

We need to write XML files to a zip file. This part of our code is 22%+ of the total processing time so optimizing this will be a big win. We're presently using dom4j to write out to a Document and then using XMLWriter to write the generated Document to the ZipOutputStream.

We need to run on Java 1.4.

The code is written so we do NOT need a DOM. We walk through writing the xml in order so if it can then write immediately to the zip stream, that would work well.

Update: We also use dom4j for XPath queries (where we do read the XML into a DOM). We can have 2 libraries but if there's an alternative that is better for both uses, that would be good too.

But for this specific need, it's pure write it out, in order (ie no DOM needed).

David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • http://stackoverflow.com/q/831865/139010 http://woodstox.codehaus.org – Matt Ball Apr 12 '13 at 22:04
  • I can't really follow your question. Are you saying you need a better way transform one XML file into another XML file that runs really well on Java 1.4? The Java 1.4 part may limit you. – Bob Kuhar Apr 12 '13 at 22:28
  • @BobKuhar - Sorry, no. I am creating the XML so it's addElement(), addAttribute(), addAttribute(), addElement(), ... So in my code I am creating the XML. But I never need to go back, all I am doing is adding elements and attributes and when done, need that written as an XML file to the zip file. – David Thielen Apr 12 '13 at 22:59
  • You should really use JAXB and schemas and nothing else. JAXB will marshall / unmarhall to Java objects from XML and back – David Brossard Jan 25 '16 at 22:42

1 Answers1

0

I think StAX produces streamed XML Output: http://stax.codehaus.org/. That would get you out of maintain a DOM in memory for the output XML.

Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115