aspose file tools*
The moose likes XML and Related Technologies and the fly likes Adding attributes to root tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Adding attributes to root tag" Watch "Adding attributes to root tag" New topic
Author

Adding attributes to root tag

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

I need Java code to read a large XML message from a database, add several attributes to the root tag, and send it out over a network. Ideally, I'd like to avoid having the entire message in core memory. Doesn't SAX allow parsing without loading the whole file? I'd appreciate some tips. The database and network stuff I can do, but the XML manipulation is baffling to me.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

A SAX filter is what you want here. There's a whole chapter of a book online that describes them:

http://www.cafeconleche.org/books/xmljava/chapters/ch08.html

I think you are hinting at what the author says in the first paragraph of that chapter: "In all of XML, I have found nothing quite so hard to understand yet easy to do as writing SAX filters."
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Adding attributes to root tag