This week's book giveaway is in the Java in General forum. We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line! See this thread for details.
I am modifying an XML file in memory. is there a standard way to write my changes out to file ?
posted 13 years ago
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.