XML resources are actually text files in XML format. These files do not need to be saved in the res \ XML directory. You can use the resources. getxml () method to obtain the xmlresourcesparser object that processes the command XML file. This process is similar to that of sax. The difference is that sax is based on the event model, while xmlresourcesparser continuously updates the current state by calling the next method. Example:
Stringbuffer sb = new stringbuffer ();
Xmlresourceparser xml = getresources (). getxml (R. xml. Android );
Try {
// Switch to the next status and obtain the type of the Current Status
Int eventtype = xml. Next ();
While (true ){
// Document start status
If (eventtype = xmlparser. start_docunment ){}
// Tag start status
If (eventtype = xmlparser. start_tag ){
// Obtain the tag name XML. getname ();
// Obtain the number of attributes of the current tag int COUNT = xml. getattributecount ();
// Obtain the names and attribute values of all attributes of the current tag.
For (INT I = 0; I <count; I ++ ){
// Attribute name XML. getattributename (I)
// Attribute value XML. getattributevalue (I)
}
}
// Tag end status
If (eventtype = xmlparser. end_tag ){}
// Read the label content status
If (eventtype = xmlparser. Text ){}
// Document end status
If (eventtype = xmlparser. end_document ){
// The document analysis is complete.
Break;
}
// Key step !!! Switch to the status to determine
Eventtype = xml. Next ();
}
}