I have a string that's has xml content in it like this:
String xml = "<item_list>" +
"<category id='2' name='categoryName'>" +
"<item id='41' name='item1' />" +
"</category>" +
"</item_list>)";
I want to convert this to an Document object. Here my code for doing this:
Document doc = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader sr = new StringReader(xml);
InputSource is = new InputSource(sr);
doc = builder.parse(is);
When I run this I get the next error:
org.xml.sax.SAXParseException: Unexpected token (position:TEXT )@1:139 in java.io.InputStreamReader@40fa7860)
What am I doing wrong?