Sax is an XML parser that is fast and consumes less memory, and is ideal for mobile devices such as Android. The Sax parsing XML file takes event-driven, that is, it does not need to parse through the entire document, and in the process of parsing the document in content order, sax determines whether the currently-read character is legitimate in the XML syntax, and triggers the event if it is compliant. The so-called events, in fact, are some callback (callback) methods, these methods (events) are defined in the ContentHandler interface. Here are some common methods for ContentHandler interfaces:
Startdocument ()
When you encounter the beginning of the document, call this method, you can do some preprocessing work.
Enddocument ()
Corresponding to the above method, when the end of the document, call this approach, you can do some cleanup work.
This method is triggered when a start tag is read. NamespaceURI is a namespace, LocalName is a label name without a namespace prefix, QName is a label name with a namespace prefix. All property names and corresponding values can be obtained by Atts. Note that one important feature of Sax is its streaming, when a tag is encountered, it does not record the previously encountered tags, that is, in the Startelement () method, all you know is the name and attributes of the tag, as for the nested structure of the tag, The name of the top tag, whether there are any other structure-related information, etc., are unknown and require your program to complete. This makes it easy for sax to be programmed without DOM.
This method corresponds to the above square method, which is called when the end tag is encountered.
Characters (char] ch, int start, int length)
This method is used to process what is read in an XML file, the first parameter is the string content of the file, and the next two parameters are the starting position and length of the read string in the array, and the content can be obtained using the new string (ch,start,length).
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.