This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 2833
    
  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: 18541
    
    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."
 
Consider Paul's rocket mass heater.
 
subject: Adding attributes to root tag
 
Similar Threads
JSP markup reuse and request parameters
JSP 2 Tag Files
XOM generating XML -> schema declaration problem
regex question, help please!
Need help with XSLT, modifying XML config files.