File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes APIs for modify existing XML 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 "APIs for modify existing XML" Watch "APIs for modify existing XML" New topic
Author

APIs for modify existing XML

Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Hi,
I've a requirement of searching for some information in an XML and modify the same file..
I've used DOM parser(DocumentBuilderFactory), but my XML size is expected to be several hundred MBs in production(and there can be very frequent edits); so working with DOM wouldn't be efficient..and streaming APIs don't support editing of the content(correct me if I'm wrong on this)..

Can someone list out the APIs with which I can do it, along with the performance comparison for this particular use case?

Thanks,
Sumeet


Sumeet
SCJP, SCWCD
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's true that streaming APIs don't allow you to edit the original document, but then neither does the DOM API. In both cases you have to do something specific to output a new version of the document.

StAX supports serializing data to an XML document, so possibly you could use that.
Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Thanks Paul, but I've edited the same file using DOM, using the setNodeValue() and setTextContent() methods of org.w3c.dom.Node interface, and then using the Document object in TransformerFactory as follows..




Am I right?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
If you really have to deal with "several hundred MB" in production, you may run out of memory using DOM methods. The reason being that each node in the document becomes an object.

IF (big if) your modifications can be handled in a single sequential pass through the document, SAX or StAX style processing will require much less memory and be quite fast.

Note that you are not really editing "the same file" but creating a new file.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Sumeet H Singh wrote:Am I right?


Yes, you're right. In that case the "something specific to output a new version of the document" was the Transformer code from lines 8 to 14 in your post; modifying the DOM didn't modify the original document. That's what I meant when I said that.
Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Tried using StAX parser..It takes much lesser time even to copy to entire file than DOM..
Thanks!

Sumeet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: APIs for modify existing XML