Xml parsing in java and android

Source: Internet
Author: User

Xml parsing in java and android

There are four classic methods for parsing xml in java:

1. dom 2.sax 3. jdom 4. dom4j I personally think dom4j is easy to use, but I have only used jdom.

Android I know using two methods: sax and pull.

The feature of the SAX method is that a complete document needs to be parsed before it is returned. If we only need the previous part of data in an XML document, the whole document will still be parsed using the SAX method, although we do not need to parse most of the data behind the XML document, this actually wastes processing resources.

The Pull parser and the SAX Parser have differences but similarities. The difference is that the SAX Parser automatically pushes events to the registered event processor for processing, so you cannot control the event processing to take the initiative to end; the Pull parser is used to allow your application code to actively retrieve events from the parser, because it is actively obtaining events, therefore, after meeting the required conditions, you can stop obtaining the event and complete the parsing. This is their main difference.

While their similarity lies in the running mode, the Pull parser also provides events similar to SAX (start documentSTART_DOCUMENTAnd end documentEND_DOCUMENT, Start ElementSTART_TAGAnd End ElementEND_TAG, Encountered Element ContentTEXT), But you need to call the next () method to extract them (actively extract events ).


Pull is an embedded xml Parsing Method in android.

The PULL parser is compact, lightweight, fast in resolution, and easy to use. It is very suitable for Android mobile devices. The Android system also uses the PULL Parser for parsing Various XML files, android officially recommends developers to use the Pull parsing technology. Pull Parsing is an open-source technology developed by a third party. It can also be used in JavaSE development.

Working principle of PULL:

XML pull provides the start and end elements. When an element starts, you can call parser. nextText to extract all characters from the XML document. An EndDocument event is automatically generated when a file is parsed to the end.



Related Article

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.