Home  >  Article  >  Backend Development  >  xml parsing sax parsing principle diagram and technical introduction

xml parsing sax parsing principle diagram and technical introduction

黄舟
黄舟Original
2017-02-16 15:25:121906browse




SAX parsing tool - provided by Sun. Built into jdk. org.xml.sax.*

##                                                                                    SAXParser class: Used to read and parse xml file objects

f,

DefaultHandler

dh) Method: Parse xml file Use the specified DefaultHandler to parse the content of the specified file into XML.

                                                                             ##                                                                                                                                                         to

Parameter two: DefaultHandler: SAX event handler. Use a subclass of DefaultHandler

For example:

{
                  1.创建SAXParser对象 
              SAXParserparser=SAXParserFactory.newInstance().newSAXParser();
                  2.调用parse方法
            parser.parse(new
 File("./src/contact.xml"),new MyDefaultHandler());
}             [一个类继承class类名(extends
 DefaultHandler) 在调用是创建传进去
 
DefaultHandler类的API:
voidstartDocument()  :  在读到文档开始时调用
voidendDocument()  :在读到文档结束时调用
void startElement(String uri, String localName, String qName,Attributes attributes)  :读到开始标签时调用                           
voidendElement(String uri, String localName, String qName)   :读到结束标签时调用
voidcharacters(char[] ch, int start, int length) :读到文本内容时调用

##Next, Let's take an example to understand the process of sax parsing xml.



The above is the content of the sax parsing schematic diagram and technical introduction of xml parsing, more For related content, please pay attention to the PHP Chinese website (

www.php.cn)!


#

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn