我想用正确的方式解析自定义android标签与XmlResourceParser。我使用的是Eclipse插件的Eclipse 3.6,我希望name
的一些属性可以从strings.xml
扩展为完整的字符串。Android自定义XML解析器无法解析android名称空间
这是在res/xml/
文件夹中正在解析的index.xml
。
<?xml version="1.0" encoding="utf-8"?>
<Index xmlns:android="http://schemas.android.com/apk/res/android">
<Sheet
shortName="o_2sq"
android:name="@string/o_2sq"
instructions=""
/>
</Index>
这里是在res/values/
夹
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="o_2sq">Organize two squares</string>
</resources>
文件strings.xml
和解析所述第一index.xml
与XmlResourceParser代码片断:
String name = xpp.getAttributeValue(null, "android:name");
String shortName = xpp.getAttributeValue(null, "shortName");
可变name
包含null
,但shortName
包含"o_2sq"
。我也尝试没有成功如下:
String name = xpp.getAttributeValue("android", "name");
什么是写句话让变量名称将包含"Organize two squares"
的正确方法是什么?
你的意思是'else {name = s'}'?看起来像这样会允许该属性是一个资源或硬编码的字符串,不是? – 2013-11-24 01:15:29
我需要的名字在我的情况下不为空。这就是为什么。 – 2013-11-25 06:37:57