问答详情
源自:3-1 使用 SAX 解析 XML 文件的开始和结束

为什么没有输出

package com.liu.test;


import java.io.IOException;

import com.liu.handler.*;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;


import org.xml.sax.SAXException;


import com.sun.org.apache.xml.internal.resolver.readers.SAXParserHandler;


public class SAXtest {

public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {

//获取一个saxparserfactory的实例

SAXParserFactory factory = SAXParserFactory.newInstance();

SAXParser parser = factory.newSAXParser();

SAXParserHandler handler = new SAXParserHandler();

parser.parse("books.xml", handler);

}

}




package com.liu.handler;


import jdk.internal.org.xml.sax.Attributes;

import jdk.internal.org.xml.sax.SAXException;

import jdk.internal.org.xml.sax.helpers.DefaultHandler;


public class SAXParserHandler extends DefaultHandler {

public void startElement(String arg0, String arg1, String arg2,

Attributes arg3) throws SAXException {

// TODO Auto-generated method stub

super.startElement(arg0, arg1, arg2, arg3);

}


public void endElement(String arg0, String arg1, String arg2)

throws SAXException {

// TODO Auto-generated method stub

super.endElement(arg0, arg1, arg2);

}

/**

* 用来标识解析开始

*/

public void startDocument() throws SAXException {

// TODO Auto-generated method stub

super.startDocument();

System.out.println("SAX解析开始");

}

/**

 * 用来标识解析结束

 */

public void endDocument() throws SAXException {

// TODO Auto-generated method stub

super.endDocument();

System.out.println("SAX解析结束");

}

  

}


提问者:tiger杰哥 2017-03-23 15:07

个回答

  • qq_顿首_0
    2017-03-24 21:50:07
    已采纳

    http://img.mukewang.com/58d523f30001324e07000282.jpg

    应该是这些包吧

  • qq_坚强_1
    2017-03-23 16:31:48

    import的包错了 删除重新引包