Working with Arbitrary XML Resource Files

In addition to the structured resources described so far, Android allows arbitrary XML files as resources. This approach extends the advantages of using resources to arbitrary XML files. This approach provides a quick way to reference these files based on their generated resource IDs. Second, the approach allows you to localize these resource XML files. Third, you can compile and store these XML files on the device efficiently.

XML files that need to be read in this fashion are stored under the /res/xml subdirectory. Listing 3–30 is an example XML file called /res/xml/test.xml.

Listing 3–30. Example XML File

<rootelem1>    <subelem1>       Hello World from an xml sub element    </subelem1> </rootelem1> ...

Get Pro Android 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.