<?xml version="1.0" encoding="gb2312"?>
<person>
<name>王小明</name>
<college>信息学院</college>
<telephone>6258113</telephone>
<notes>男,1955年生,博士,95年调入海南大学</notes>
</person>
事件回调类SAXHandler.java
import java.io.*;
import java.util.Hashtable;
import org.xml.sax.*;
public class SAXHandler extends HandlerBase {
private Hashtable table = new Hashtable();
private String currentElement = null;
private String currentValue = null;
public void setTable(Hashtable table) {
this.table = table;
}
public Hashtable getTable() {
return table;
}
public void startElement(String tag, AttributeList attrs) throws SAXException {
currentElement = tag;
}
public void characters(char[] ch, int start, int length) throws SAXException {
currentValue = new String(ch, start, length);
}
public void endElement(String name) throws SAXException {
if (currentElement.equals(name)) {
table.put(currentElement, currentValue);
}
}
}