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

📄 xmltransform.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 JAVA
字号:
/*
 * WebLogic Server Unleashed
 */
package com.wlsunleashed.xml.transform;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
 * This class provides a simple transformation for the booklist.xml 
 * document using the booklist.xsl stylesheet and prints out the output
 * in html format onto the standard out. 
 * 
 * @author WebLogic Server Unleashed
 *
 */
public class XMLTransform {

	/**
	 * The location of the XML document 
	 */
	private static final String XML_DOCUMENT = "./booklist.xml";
	
	/**
	 * The location of the stylesheet
	 */
	private static final String STYLESHEET = "./booklist.xsl";
	
	/**
	 * The main method of this class. 
	 * 
	 * @param args any arguments passed in. This class does not
	 * expect any arguments to be passed in.
	 */
    public static void main(String[] args) {

		String document = XML_DOCUMENT;
		String stylesheet = STYLESHEET;
		// If passed in, use the XML and XSL files.
		if (args.length >= 1) {
			document = args[0];
		}
		if (args.length >= 2) {
			stylesheet = args[1];
		}
		try {
			TransformerFactory tf = 
				TransformerFactory.newInstance();
		
	//		   Create the transformer for the given stylesheet
			Transformer transformer = 
				tf.newTransformer(new StreamSource(stylesheet));
	//		Transform the XML document giving the source and 
	//		destination streams
			FileInputStream source = new FileInputStream(document);
			transformer.transform(new StreamSource(source),
				 new StreamResult(System.out));

		}
		catch (TransformerConfigurationException tce) {
			tce.printStackTrace();    	
		}
		catch (FileNotFoundException fnfe) {
			fnfe.printStackTrace() ;
		}
		catch (TransformerException te) {
			te.printStackTrace() ;
		}
    }
}

⌨️ 快捷键说明

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