I have an XML index in the res/xml/ folder, and I would like it to include other xml files, so that when I parse R.xml.index, all the files are merged into a single resource.
I tried to adapt the include layout trick to xml parsing, so my index.xml looks like that :
<?xml version="1.0" encoding="utf-8"?>
<Index xmlns:android="http://schemas.android.com/apk/res/android">
<Sheet>
<include xml="o_2sq_m.xml"/>
<include xml="o_2sq_r.xml"/>
</Sheet>
<Sheet>
<include xml="o_sq_tr_m.xml"/>
<include xml="o_sq_tr_r.xml"/>
</Sheet>
</Index>
and the file o_2sq_m.xml, which is in the same folder as index.xml, looks like that:
<?xml version="1.0" encoding="UTF-8"?>
<Challenge xmlns:android="http://schemas.android.com/apk/res/android">
<Dimensions maxX="512" maxY="342" />
<Point id="1" x="94" y="101" color="0x00000000" />
...
</Challenge>
But when I parse index.xml with and XmlPullParser, I see in the debugger that it parses the include tags without having them unrolled, i.e. it does not access the tree of the file o_2sq_m.xml
What should I do to have android include the files within one other ?
If you are not doing too much XML import (such as at create time), you could use
getResources().getIdentifier(), which for an index like that (remove the.xmlin the attribute)and given that your file to be included is named
o_2sq_m.xml, you could use the following code: