aspose file tools*
The moose likes XML and Related Technologies and the fly likes Serialize XML with JAXP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Serialize XML with JAXP" Watch "Serialize XML with JAXP" New topic
Author

Serialize XML with JAXP

Ronald Francis
Ranch Hand

Joined: Aug 02, 2001
Posts: 30
I am modifying an XML file in memory. is there a standard way to write my changes out to file ?
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
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.
 
wood burning stoves
 
subject: Serialize XML with JAXP