Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert dom4j document object to string

Tags:

java

dom

dom4j

Just trying to find a way to convert a Dom4J Document content to String. It has a asXML() API which converts the content to a XML. In my case,I'm editing a non-xml DOM structure using Dom4J and trying to convert the content to String. I know its possible in case of w3c document.

Any pointers will be appreciated.

Thanks

like image 527
Shamik Avatar asked Apr 07 '11 01:04

Shamik


People also ask

How do I convert a file to string in Java?

Document convertStringToDocument(String xmlStr) : This method will take input as String and then convert it to DOM Document and return it. We will use InputSource and StringReader for this conversion. String convertDocumentToString(Document doc) : This method will take input as Document and convert it to String.

Can we convert string to XML in Java?

Java Code to Convert String to XML DocumentTo convert the String to XML document, we will use DocumentBuilderFactory and DocumentBuilder classes. "</BookStore>"; //Call method to convert XML string content to XML Document object.


1 Answers

asXml() return String from Document object

String text = document.asXML()
like image 108
James Avatar answered Sep 29 '22 16:09

James