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
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.
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.
asXml() return String from Document object
String text = document.asXML()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With