Java 使用SAX解析器,获取一个属性';s值
我正在使用Android解析web上的XML。下面的代码显示了XML的一个示例。我遇到的问题是无法获取item标记的字符串值。当我使用Java 使用SAX解析器,获取一个属性';s值,java,android,xml,saxparser,xml-attribute,Java,Android,Xml,Saxparser,Xml Attribute,我正在使用Android解析web上的XML。下面的代码显示了XML的一个示例。我遇到的问题是无法获取item标记的字符串值。当我使用name=attributes.getQName(I)时它输出的是名称,而不是属性的值 <weatherdata> <timetags> <item name="date"> <value>20/04/2012</value> <unit/> <image/>
name=attributes.getQName(I)时代码>它输出的是名称,而不是属性的值
<weatherdata>
<timetags>
<item name="date">
<value>20/04/2012</value>
<unit/>
<image/>
<class>dynamic</class>
<description>The current date</description>
</item>
20/04/2012
动态
当前日期
使用
而不是
attributes.getQName(i);
因为正如所说:
getQName:返回属性的限定(前缀)名称
getValue:通过限定(前缀)名称查找属性的值
有关获取属性名称和值的示例,请参见
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if(localName.equalsIgnoreCase("item")){
//currentMessage.setMediaUrl(attributes.getValue(BaseFeedParser.Url));
String valueis=attributes.getValue("name")
}
super.startElement(uri, localName, qName, attributes);
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if(localName.equalsIgnoreCase("item")){
//currentMessage.setMediaUrl(attributes.getValue(BaseFeedParser.Url));
String valueis=attributes.getValue("name")
}
super.startElement(uri, localName, qName, attributes);
}