1
我有一些字符串的XML文件:XMLPullParser Android的测试属性
<string>foo</string>
和一些字符串包含一个href属性:
<string href="http://www.google.com/">foo2</string>
我使用XMLPullParser在我的Android解析这个XML应用程序。但是,我需要能够测试xml元素是否包含href属性。或者就此而言任何属性。 我试过用这个:
private boolean testForHref(String tag) throws IOException, XmlPullParserException{
try{
parser.getAttributeValue(NULL, tag);
System.out.println("href attribute is here!");
return true;
}catch (Exception e){
System.out.println("href attribute is not here!");
return false;
}
}
但是这总是返回false。有谁知道如何做这个测试?
这使返回这个空:<字符串HREF = “http://10.80.30.10/tracker”>问题跟踪 –
@BlackMagic它会奏效。我不知道你是如何做我们的解析。 – Raghunandan
@BlackMagic检查我试过的编辑之前发布它 – Raghunandan