Files in RES/XML

Source: Internet
Author: User

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 ();

}

        

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.