Working with XML Files

The XML file format is well supported on the Android platform. Arbitrary XML files can be included as resources. These XML files are stored in the /res/xml directory. XML file resources are the preferred format for any structured data your application requires.

How you format your XML resource files is up to you. A variety of XML utilities (shown in Table 4.5) are available as part of the Android platform.

TABLE 4.5 XML Utility Packages

Package

Description android.sax.*

android.util.Xml.'

javax.xml.*

org.w3c.dom org.xmlpull.*

Framework to write standard SAX handlers XML utilities, including the XMLPullParser Core SAX functionality (see www.saxproject.org) SAX and limited DOM, Level 2 core support Interfaces for DOM, Level 2 core XmlPullParser and XMLSerializer interfaces (see www.xmlpull.org)

To access an XML file called /res/xml/default_values.xml programmatically, you could use the getXml() method, like this:

XmlResourceParser defaultDataConfig = getResources().getXml(R.xml.default_values);

0 0

Post a comment