My code
InputStream ins = getResources().openRawResource(
getResources().getIdentifier("state",
"raw", getPackageName()));
DocumentBuilder docBuilder = null;
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setIgnoringElementContentWhitespace(true);
docBuilder = f.newDocumentBuilder();
state = docBuilder.parse(ins);
ins.close();
The xml to understand what happens
<?xml version="1.0" encoding="utf-8"?>
<State xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<IsOff>false</IsOff>
</State>
And the result you can see as \n; IsOff and \n
Also, you can see that I've set
f.setIgnoringElementContentWhitespace(true);
This XML would come from anywhere, so it is unacceptable to have such parsing results. Also, whiteSpaces would be inside text data of the document. So mechanically removing all Spaces; \n \t \r is not the answer. It is task of the parser to skip extra spaces and other chars between tags, right?