如何采用了android SAX解析器解析与XML命名空间 [英] How to parse xml with namespace using android sax parser
本文介绍了如何采用了android SAX解析器解析与XML命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的XML文档看起来是这样的:
My XML Document looks like this:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<feed xml:base="http://localhost/someApp" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<entry>
<id>An ID here</id>
<content type="application/xml">
<m:properties>
<d:Name>The name I want to get</d:Name>
</m:properties>
</content>
</entry>
</feed>
我能够从 ID这里有一个ID获得
这个code标记:
String ATOM_NAMESPACE = "http://www.w3.org/2005/Atom";
RootElement root = new RootElement(ATOM_NAMESPACE, "feed");
Element entry = root.getChild(ATOM_NAMESPACE, "entry");
Element id = entry.getChild(ATOM_NAMESPACE, "id");
id.setEndTextElementListener(new EndTextElementListener(){
public void end(String body){
messages.add(body); // messages = ArrayList<String>
}
});
不过,我似乎无法得到我想要得到的名字。
However, I can't seem to get "The name I want to get".
我添加了这个$ C $ C:
I added this code:
String METADATA_NAMESPACE = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
String DATASERVICES_NAMESPACE = "http://schemas.microsoft.com/ado/2007/08/dataservices";
Element content = entry.getChild(ATOM_NAMESPACE, "content");
Element properties = content.getChild(METADATA_NAMESPACE, "properties");
Element name = properties.getChild(DATASERVICES_NAMESPACE, "name");
name.setEndTextElementListener(new EndTextElementListener(){
public void end(String body){
messages.add(body);
}
});
但没有被添加消息列表中。
but nothing gets added the messages list.
我需要什么才能做的就是 D:名称
What do I need to do in order to get d:Name
?
推荐答案
好视G_H指出,问题是我没有资本名
Well as G_H pointed out the problem was I wasn't capitalizing "name"
本作品:
Element name = properties.getChild(DATASERVICES_NAMESPACE, "Name"); // 'Name' instead of 'name'
name.setEndTextElementListener(new EndTextElementListener(){
public void end(String body){
messages.add(body);
}
});
这篇关于如何采用了android SAX解析器解析与XML命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文