Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6946115
  • 博文数量: 701
  • 博客积分: 10821
  • 博客等级: 上将
  • 技术积分: 12021
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-02 10:41
个人简介

中科院架构师,专注企业数字化各个方面,MES/ERP/CRM/OA、物联网、传感器、大数据、ML、AI、云计算openstack、Linux、SpringCloud。

文章分类

全部博文(701)

分类: Java

2013-04-26 15:57:30

import java.util.ArrayList;
import java.util.List;

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

public class XercesTest extends DefaultHandler {
//    static{
//        System.out.print("AAA");
//        System.exit(0);
//    }
    /**
     * 一段使用Xerces解析XML的例子。
     * @param args
     */
    public static void main(String[] args) throws Exception {
       System.out.println("hello world!");
       //(new XercesTest()).run(args[0]);
       (new XercesTest()).run("member.xml");
    }

    public void run(String file) throws Exception {
       
        XMLReader parser = XMLReaderFactory.createXMLReader();
        parser.setContentHandler(this);
        parser.parse(file);
    }

    public void startDocument() throws SAXException {
        System.out.println("starting parse XML file....");
    }

    public void startElement(String uri, String localName, String rawName, Attributes attlist) throws SAXException {
        System.out.println(localName);
    }

    public void endElement(String uri, String localName, String rawName) throws SAXException {
    }

    public void characters(char[] ch, int start, int length) throws SAXException {
        System.out.println(new String(ch, start, length));
    }

    public void endDocument() throws SAXException {
        System.out.println("end parse XML file!");
    }
}

member.xml


  wangxiaoming
  infor school 
  6258113
  man,from 1955 year,doctor,In hainan university from 1995

阅读(2462) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~