
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | {
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) :读到文本内容时调用
|
Copy after login
##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)!
#