• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Result (JAXP)

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In JAXP library,

What is the difference among
SAXResult
DOMResult
StreamResult ?

And which is better to use?

I have HashMap with data filled in it. Now i need to generate XML file with contents in this HashMap. For doing this i want to use JAXP and SAX and serialize the data to a file.

Is there any particular site which gives me how to generate XML using JAXP+SAX+Serialization.

thanks in advance
required very urgent

Suresh Appagundi
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Suresh Appagundi:
In JAXP library,
What is the difference among
SAXResult
DOMResult
StreamResult ?

And which is better to use?


The implementations of javax.xml.transform.Result are used as the "output stream" for javax.xml.transform.Transformer#transform(Source, Result).

SAXResult is a class which takes the transformation result and feeds it into the SAX handler you've given it (usually passed to it in its constructor).

DOMResult acts as a wrapper for the DOM tree generated by the transformation. After calling myTransformer.transform(mySource, myDomResult), you can do myDomResult.getNode() and it returns the resulting DOM tree's root node.

StreamResult acts as a serializer component by taking the result of the transformation and writing it into an OutputStream as "raw" XML.

Which of these you should use is completely dependent on your situation and what you want to accomplish?

Originally posted by Suresh Appagundi:
I have HashMap with data filled in it. Now i need to generate XML file with contents in this HashMap. For doing this i want to use JAXP and SAX and serialize the data to a file.


You could write an implementation of ContentHandler which reacts to SAX events (startElement, characters, endElement, etc.) by writing matching XML constructs into an OutputStream and then just call the relevant methods for each entry in your HashMap.

Another option would be to create a DOM tree and then serialize that in the end using javax.xml.transform.Transformer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic