}
public void startElement(String uri, String localName, String qName,
Attributes attrs) {
tags.push(qName);
}
public void characters(char ch[], int start, int length)
throws SAXException {
String tag = (String) tags.peek();
if (tag.equals("name")) {
System.out.println("Name|" + new String(ch, start, length));
}
else if (tag.equals("space")) {
System.out.println("Space|" + new String(ch, start, length));
}
}
public void JDOM() {
long start = System.currentTimeMillis();
try {
SAXBuilder builder = new SAXBuilder();
org.jdom.Document doc = builder.build(f);
Element foo = doc.getRootElement();
List< > allChaildren = foo.getChildren();
for (int i = 0; i < allChaildren.size(); i++) {
System.out.println("Name|"
+ ((Element) allChaildren.get(i)).getChild("name")
.getText());
System.out.println("Space"
+ ((Element) allChaildren.get(i)).getChild("space")
.getText());
}
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("jdom runtime" + (end - start) + "MS");
}
public void DOM4J() {
long start = System.currentTimeMillis();
try {
SAXReader reader = new SAXReader();
org.dom4j.Document doc = reader.read(f);
org.dom4j.Element root = doc.getRootElement();
org.dom4j.Element foo;
for (@SuppressWarnings("rawtypes")
java.util.Iterator i = root.elementIterator("node"); i.hasNext();) {
foo = (org.dom4j.Element) i.next();
System.out.println("Name|"
+ ((org.dom4j.Element) foo).elementText("name"));
System.out.println("Space|"
+ ((org.dom4j.Element) foo).elementText("space"));
}
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("dom4j runtime" + (end - start) + "MS");
}
}
package senior;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Stack;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.D