I try to parse an XML and get the following error, what could the problem be?
I/System.out(8058): Wrong XML file structure: Unexpected token (position:TEXT @1:2 in java.io.StringReader@4113db88)
Thats the method I parse with
public final static Document XMLfromString(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
System.out.println("XML parse error: " + e.getMessage());
return null;
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
System.out.println("I/O exeption: " + e.getMessage());
return null;
}
return doc;
}
And thats the XML I try to parse:
<?xml version="1.0" encoding="UTF-8"?>
<app>
<Date Value="02.07.2012">
</Date>
</app>