欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SAX解析XML文件

程序员文章站 2022-03-03 15:06:18
...

books.xml

<?xml version="1.0" encoding="UTF-8" ?>
<bookstore>

    <book id = "1">
        <name>冰与火之歌</name>
        <author>
            <phone>123123</phone>
            <email>
                <qq>13dpwe</qq>
            </email>
        </author>
        <year>2014</year>
        <price>89</price>
    </book>
    <book id = "2">
        <name>安徒生童话</name>

        <year>2014</year>
        <price>77</price>
        <language>English</language>
    </book>
</bookstore>

SAXParse.java

package com.uplooking.dom;

import com.uplooking.bean.Book;
import com.uplooking.bean.Resource;
import com.uplooking.sax.MyDefaultHandler;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

impo