I have a XML in String variable and I want to pass that value into the parse() of DocumentBuilder.
String xml = "<?xml version="1.0 ....>";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xml)));
But, seems like the last line doesnt work as doc is null.
Is there anything wrong with this? I am just trying take a xml value and convert it to Document.
Thanks for help.
You need something nearer
You can trim this to:
Note that normally you’d expect an XML File and it’d be: