I'm trying to parse an XML document on Android 2.3.3, but it seems that there is no validating parser. The reason I need validation for is to ignore whitespaces in the XML file (blanks, carriage returns, line feeds, etc.).
Thats how I want to parse the document:
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
dbfac.setValidating(true);
dbfac.setIgnoringElementContentWhitespace(true);
DocumentBuilder docBuilder;
docBuilder = dbfac.newDocumentBuilder();
Document d = docBuilder.parse(file);
file
is the URL to the file location as string. When executing the last line of this code the following exception is thrown:
javax.xml.parsers.ParserConfigurationException: No validating DocumentBuilder implementation available
When I take out dbfac.setValidating(true)
, no exception occurs, but then I have the problem with the whitespaces.
Does anyone know how to solve this problem? Do I have to use another parser?