xerces

xerces

Xerces是一個開放源代碼的XML語法分析器。 Xerces-J。 org.xml.sax.XMLReader;import

簡介


Xerces是由Apache組織所推動的一項XML文檔解析開源項目,它目前有多種語言版本包括JAVA、C++、PERL、COM等。
Xerces是一個開放源代碼的XML語法分析器。從JDK1.5以後,Xerces就成了JDK的XML默認實現
Xerces-C++ 的前身是 IBM 的 XML4C 項目。XML4C 和 XML4J 是兩個並列的項目,而 XML4J 是 Xerces-J——Java 實現——的前身。IBM 將這兩個項目的源代碼讓與 Apache 軟體基金會(Apache Software Foundation),他們將其分別改名為 Xerces-C++ 和 Xerces-J。註:“Xerces-C”和“Xerces-C++”是同一個東西。

例子


package net.java2000.xerces;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
public class XercesTest extends DefaultHandler {
public static void main(String args[]) throws Exception {
(new XercesTest()).run(args);
}
public void run(String file) throws Exception {
XMLReader parser = new SAXParser();
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!");
}
}