xerces

王朝百科·作者佚名  2010-01-28  
宽屏版  字体: |||超大  

介绍Xerces是一个开放源代码的XML语法分析器。

Xerces-C++ 的前身是 IBM 的 XML4C 项目。XML4C 和 XML4J 是两个并列的项目,而 XML4J 是 Xerces-J——Java 实现——的前身。IBM 将这两个项目的源代码让与 Apache 软件基金会(Apache Software Foundation),他们将其分别改名为 Xerces-C++ 和 Xerces-J。注:“Xerces-C”和“Xerces-C++”是同一个东西。

Xerces_J的一个例子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;

/**

* 一段使用Xerces解析XML的例子。

*

* @author 赵学庆,Java世纪网(java2000.net)

*

*/

public class XercesTest extends DefaultHandler {

public static void main(String args[]) throws Exception {

(new XercesTest()).run(args[0]);

}

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!");

}

}

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有