convert xml document to string using kxml2 library

777 Views Asked by At

I need to convert XML document with kxml2 lib to string. Here I create the document using kxml: org.kxml2.kdom.Document doc = new org.kxml2.kdom.Document(); org.kxml2.kdom.Element command = doc.createElement("", "parent"); command.setName("command"); org.kxml2.kdom.Element text = doc.createElement("", "child"); text.setName("text"); KXmlParser parser= new KXmlParser(); text.addChild(0, org.kxml2.kdom.Node.TEXT, textmessage); command.addChild(0, org.kxml2.kdom.Node.ELEMENT, text); doc.addChild(0, org.kxml2.kdom.Node.ELEMENT, command);

So how can I convert the doc to string? Sample code will be great help. Thank you !

1

There are 1 best solutions below

0
On

According to the documentation of org.kxml2.kdom.Document you can use doc.write(writer) to serialize your XML document.

Here is an example of how you can acquire a org.xmlpull.v1.XmlSerializer: http://www.extreme.indiana.edu/xmlpull-website/xmlpull-website-redesign/v1/doc/quick_write.html