In C# we use serializer.ToXmlString/F开发者_开发百科romXmlString. Is there any Java equivalent for this?
In java you use a javax.xml.transform.Transformer for DOM objects.
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(new DOMSource(myDocument), new StreamResult(targetFile));
For regular java objects you might want to try XStream.
精彩评论