I'm trying to parse an iPhone plist file to use it with xpath and xpathexpression.
plist example:
<plist version="1.0">
<dict>
<key>00</key>
<dict>
<key>pkw</key>
<dict>
<key>gas</key>
<integer>0</integer>
<key>diesel</key>
<dict>
<key>ohne</key>
<integer>0</integer>
<key>pm01</key>
<integer>0</integer>
<key>pm0</key>
<integer>0</integer>
<key>pm1</key>
<integer>0</integer>
<key>pm2</key>
<integer>0</integer>
<key>pm3</key>
<integer>0</integer>
<key>pm4</key>
<integer>0</integer>
<key>pm5</key>
<integer>4</integer>
</dict>
<key>otto</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
With the following code I'm getting a SAXParserException
name expected (position:START_TAG @3:41 in java.io.InputStreamReader@43e395f0)
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder builder = null;
try {
builder = builderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Document document = null;
try {
document = builder.parse(getApplicationContext().getResources().openRawResource(R.xml.finedust));
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Maybe someone has an idea?
The problem is, that you are trying to load the plist xml document from the res/xml/ folder (R.xml.finedust) as a raw resource.
You should put your xml file inside the res/raw/ folder (res/raw/findedust.xml), and access it by R.raw.finedust.
So your document initialization will be:
document = builder.parse(getApplicationContext().getResources().
openRawResource(R.raw.finedust));
This way it will work!
Deprecated
You have 4 <dict> tags opened but only 3 of them have the matching close tags.
One of your <dict> tag - probably the first - is not closed! You should check your input, and when you figure it out, close it, then it will parse the xml.
The parsing cannot be done unless the document is well-formed (not necessarily valid though).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With