I would like to get the correct way of parsing custom android tags with an XmlResourceParser. I am using Eclipse 3.6 with the android plug-in, and I would like some attributes like the name
be expanded with the full string from strings.xml
.
Here is the index.xml
which is being parsed in the res/xml/
folder.
<?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>
Here is the file strings.xml
in the res/values/
folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="o_2sq">Organize two squares</string>
</resources>
and the code fragment that parses the first index.xml
with an XmlResourceParser:
String name = xpp.getAttributeValue(null, "android:name");
String shortName = xpp.getAttributeValue(null, "shortName");
The variable name
contains null
, but shortName
contains "o_2sq"
. I also tried the following without success:
String name = xpp.getAttributeValue("android", "name");
What is the correct way of writing the sentence so that the variable name would contain "Organize two squares"
?
else { name = s' }
? Seems like that would allow that attribute to be either a resource or a hard-coded string, no? – Crampton