How Java and Android parse XML

Source: Internet
Author: User

There are four ways in which Java parses XML classics:

1.dom 2.sax 3.jdom 4.dom4j personally feel dom4j useful, but I only used jdom.

Android I know in two ways sax and pull

SAXthe way is characterized by the need to parse out the entire document before it is returned, if in aXMLin the documentation we only need the previous part of the data, but usingSAXThe entire document will still be parsed, althoughXMLmost of the data later in the document we don't really need to parse, so this actually wastes the processing resources.

The pull parser and SAX parser are different but have similarities. The difference is that the SAX parser works by automatically pushing events into the registered event handler, so you can't control the active end of the event's processing, and the pull parser works by allowing your application code to proactively get events from the parser, just because it's actively getting events, Therefore, you can no longer get the event after the desired condition has been satisfied, ending the parsing. This is the main difference between them.

And their similarity in the run mode, the pull parser also provides a sax-like event (Start document start_document and end document end_document, start element Start_tag and end element End_tag, Encounter element content text , etc.), but need to call the next () method to extract them (active fetch event).


Pull is a way of parsing XML embedded in Android.

PullThe parser is compact, lightweight, quick to parse and easy to use, ideal forAndroidused in mobile devices,Androidthe system internally resolves variousXMLis also used PullParser,AndroidIt is recommended that developers use Pullanalytical techniques. PullAnalytic technology is a third-party development of Open source technology, it can also be applied toJavasedevelopment.

PULL  How it works:

XML Pull the start and end elements are provided. When an element starts, you can call parser. nexttext extracts all character data from the XML document. The enddocument event is automatically generated when parsing to the end of a document.



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.