⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplesaxreporter.java

📁 使用方法: 实例程序的运行: 每个实例下都有本实例的.xml文件或.html文件或.xsl文件
💻 JAVA
字号:
package com.javaworld.mar2000.sax;

/*
 * Sample code for "SAX Appeal", by Mark Johnson, JavaWorld, March 2000.
 * Code is may be used for any legal purpose, including commercial
 * purposes, with no warranty expressed or implied.
 * email: mark.johnson@javaworld.com
 */
import org.xml.sax.*;
import org.xml.sax.helpers.ParserFactory;

/**
 * Simple class demonstrates how to use SAX by reporting all SAX events
 */
public class SimpleSaxReporter implements org.xml.sax.DocumentHandler {

public SimpleSaxReporter() {
	super();
}
/**
 * Handle incoming characters event
 */
public void characters(char[] arg1, int arg2, int arg3) throws org.xml.sax.SAXException {
	System.out.println("\"" + new String(arg1, arg2, arg3) + "\"");
	System.out.println("%%% characters(\"" + new String(arg1, 0, 10) + "...\", " +
		arg2 + ", " + arg3);
}
/**
 * Handle endDocument event.
 */
public void endDocument() throws org.xml.sax.SAXException {
	System.out.println("[End of document]");
	System.out.println("%%%endDocument()");
}
/**
 * Handle endElement event.
 */
public void endElement(String arg1) throws org.xml.sax.SAXException {
	System.out.println("</" + arg1 + ">");
	System.out.println("%%%endElement(\"" + arg1 + "\"");
}
/**
 * Handle ignorableWhitespace event.
 */
public void ignorableWhitespace(char[] arg1, int arg2, int arg3) throws org.xml.sax.SAXException {
	System.out.println("\"" + new String(arg1, arg2, arg3) + "\"");
	System.out.println("%%% ignorableWhitespace(\"" + new String(arg1, 0, 10) + "...\", " +
		arg2 + ", " + arg3);
}
	/**
	 * Create parser and SimpleSaxReporter, then parse file.
	 */
public static void main(String args[]) {
	SimpleSaxReporter ssr = new SimpleSaxReporter();
	try {
		Parser parser = ParserFactory.makeParser("com.ibm.xml.parsers.SAXParser");
		parser.setDocumentHandler(ssr);
		parser.parse(new InputSource(args[0]));
	} catch (Exception ex) {
		System.err.println(ex); // OK, so sometimes laziness *isn't* a virtue.
	}
}
/**
 * Handle processingInstruction event.
 */
public void processingInstruction(String arg1, String arg2) throws org.xml.sax.SAXException {
}
/**
 * Handle setDocumentLocator event.
 */
public void setDocumentLocator(org.xml.sax.Locator arg1) {
}
/**
 * Handle startDocument event.
 */
public void startDocument() throws org.xml.sax.SAXException {
	System.out.println("[Beginning of document]");
	System.out.println("%%%startDocument()");
}
/**
 * Handle startElement event.
 */
public void startElement(String arg1, org.xml.sax.AttributeList arg2) throws org.xml.sax.SAXException {
	System.out.println("</" + arg1 + ">");
	System.out.println("%%%startElement(\"" + arg1 + "\", [AttributeList]");
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -