[英]Android parsing plist to document
I'm trying to parse an iPhone plist file to use it with xpath and xpathexpression. 我正在尝试解析iPhone plist文件以将其与xpath和xpathexpression一起使用。
plist example: plist示例:
<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
使用以下代码我得到一个
SAXParserException
name expected (position:START_TAG @3:41 in java.io.InputStreamReader@43e395f0)
预期名称(位置:在java.io.InputStreamReader@43e395f0中START_TAG @ 3:41)
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. 问题是,您正在尝试从res / xml /文件夹(
R.xml.finedust
)中加载plist xml文档作为原始资源。
You should put your xml file inside the res/raw/ folder (res/raw/findedust.xml), and access it by R.raw.finedust
. 您应该将您的xml文件放在res / raw /文件夹(res / raw / findedust.xml)中,并通过
R.raw.finedust
访问它。
So your document
initialization will be: 所以你的
document
初始化将是:
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. 您已打开4个
<dict>
标签,但只有3个具有匹配的关闭标签。
One of your <dict>
tag - probably the first - is not closed! 您的
<dict>
标签之一 - 可能是第一个 - 未关闭! You should check your input, and when you figure it out, close it, then it will parse the xml. 你应该检查你的输入,当你搞清楚时,关闭它,然后它会解析xml。
The parsing cannot be done unless the document is well-formed (not necessarily valid though). 除非文档格式正确(但不一定有效),否则无法进行解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.