Sax: saxparserfactory and saxparser

Source: Internet
Author: User
Tags protected constructor

Sax is short for Simple API for XML. It provides an interface for parsing XML files in Android. If you want to parse an XML file, we can use the sax technology. In actual use, each character in the XML file is read one by one and corresponding events are initiated. That is to say, the sax technology is event-driven. For example, startdocument, startelement, characters, and endelement.

Instance source code:

 1   Public List <person> getpersons (inputstream instream) Throws Throwable
2
3 {
4 Saxparserfactory factory = saxparserfactory. newinstance ();
5 Saxparser parser = factory. newsaxparser ();
6 // Customize the extension of the ulthandler subclass, override some of the methods we need to parse XML
7 Personparser = New Personparser ();
8 Parser. parse (instream, personparser );
9 // Close the input stream after it is used.
10 Instream. Close ();
11 Return Personparser. getpersons ();
12
13 }

Saxparserfactory introduction:

Defines an API factory for ApplicationsProgramYou can configure and obtain a simple API for XML

) To parse the XML document (Original: defines a factory API that enables applications to configure and obtain a sax based parser to parse XML documents .)

Its constructor is protected, so it can only use the newinstance () method to obtain the instance (protected constructor to force use of newinstance ().)

Saxparser introduction:

Defines an API inherited from the xmlreader class, and its constructor is also protected. The instance is obtained through the newsaxparser () method, various data sources can be used as XML for parsing (this method is public void parse (inputsource is, defaulthandler DH). These input data sources include input streams, files, URLs, And sax input resources. (Defines the API that wraps an xmlreader implementation class, an instance of this class can be obtained from the newsaxparser () method. once an instance of this class is obtained, XML can be parsed from a variety of input sources. these input sources are inputstreams, files, URLs, And sax inputsources .)

For more information about the use of sax, I will also write an 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.