SAX解析XML

package xml;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Wangjianxin on 2017/8/4 0004.
 */
public class saxSql {


    public static void main(final String[] args) {

        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        try {
            SAXParser parser = saxParserFactory.newSAXParser();
            parser.parse("D:\\car\\car-service\\src\\main\\resources\\com\\car\\service\\mapping\\ActivityCzMapper.xml",new DefaultHandler(){
                private  int selectnum = 0;
                private  String value = null;
                private  List sqlList = new LinkedList();
                @Override
                public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                    super.startElement(uri, localName, qName, attributes);

                    if(qName.equals("select")){
                        selectnum ++;
                       int len = attributes.getLength();
                       for(int i =0;i

你可能感兴趣的:(SAX解析XML)