• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

APIs for modify existing XML

 
Sumeet H Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried using StAX parser..It takes much lesser time even to copy to entire file than DOM..
Thanks!

Sumeet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic