• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialize XML with JAXP

 
Ronald Francis
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am modifying an XML file in memory. is there a standard way to write my changes out to file ?
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ronald Francis:
I am modifying an XML file in memory. is there a standard way to write my changes out to file ?

yes take a look @ the javax.xml.transform.Result interface and it's implementations in packages
javax.xml.transform.stream ( for ur case sicne you want to serialize),
javax.xml.transform.dom,
javax.xml.transform.sax,
But you w'd be required to do a transformation!
on the XML file that you have in memory.
Then use an identity stylesheet (ie invoke the no-argument newTransformer() method to obtain the TransformerFactory instance) and then do a transform() providing the appropriate implemenation of the Result interface.
You can use StreamResult for your case.
I guess that's the only way you can serialize a in-meomory xml to a file using "JAXP".
Ofcourse parsers provide better ways of serializing the in-memory representation of XML file which in turn are not portable across parsers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic