MySAX.java
资源名称:xml001.rar [点击查看]
上传用户:zhaokuo188
上传日期:2022-05-16
资源大小:989k
文件大小:1k
源码类别:
xml/soap/webservice
开发平台:
Java
- package com.waytojob.xml;
- import java.io.File;
- import java.io.IOException;
- import java.util.HashMap;
- import javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.xml.sax.SAXException;
- public class MySAX {
- /**
- * @param args
- */
- public static void main(String[] args) {
- try {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- File file = new File("c:/dbinfo.xml");
- MyDefaultHandler dh = new MyDefaultHandler();
- parser.parse(file, dh);
- HashMap<String, String> hm = dh.getHm();
- for (String key : hm.keySet()) {
- System.out.println(key + "=" + hm.get(key));
- }
- } catch (ParserConfigurationException e) {
- e.printStackTrace();
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }