Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string to xml

Tags:

java

xml

I have a string which contains XML data and I want to convert it to XML document object. How do I do that?

like image 542
yogsma Avatar asked Sep 09 '26 16:09

yogsma


1 Answers

say theString holds the XML,

        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
        Document doc = docBuilder.parse(new InputSource(new StringReader(theString)));

More info here

like image 94
Preet Sangha Avatar answered Sep 12 '26 06:09

Preet Sangha