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

📄 transformdemo.java

📁 java核心编程的部分源码
💻 JAVA
字号:
 import javax.xml.transform.*;
import javax.xml.transform.stream.*;

/**
* TransformDemo uses JAXP to acquire an XML Transformer. It uses the Transformer
* to transform an XML shopping cart into an HTML view of the shopping cart.
* The Transformer uses transform instructions in an XSLT (.xsl) file.
*
* The following JARs must be in your CLASSPATH:
* - jaxp.jar
* - xerces.jar (for SAX parser and DOM object implementations)
* - xalan.jar (for XSLT implementation)
*
* Download JAXP (which includes these JARs) here: http://java.sun.com/xml/
* Find additional Xerces and Xalan info here: http://xml.apache.org/
*
* Note: XSLT authoring/programming is beyond the scope of this tutorial.
* You"ll find good XSL info here: http://www.w3.org/Style/XSL/#learning
**/

public class TransformDemo
{

public static void main( String[] args )
{
try
{
TransformerFactory factory = TransformerFactory.newInstance();
System.out.println( "TransformerFactory classname: " + factory.getClass().getName() );

Transformer transformer = factory.newTransformer( new StreamSource( "cart.xsl" ) );
System.out.println( "Transformer classname: " + transformer.getClass().getName() );

//This single line applies the XSL file to transform the XML into HTML.
transformer.transform( new StreamSource( "cart.xml" ), new StreamResult( System.out ) );
}
catch( Exception e )
{
e.printStackTrace();
}

}

} 

⌨️ 快捷键说明

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