关闭

Simple JAXP

546人阅读 评论(0) 收藏 举报

/*
Created on 2005–9-5
**/
package hp.alex.jaxp;

/**
@author wanbin
*/
import java.io.File;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
/**
A simple demo of JAXP 1.1
*/
public class SimpleJAXP {
/**
Accept two command line arguments: the name of an XML file, and the name
of an XSLT stylesheet. The result of the transformation is written to stdout.
*/
public static void main(String[] args) throws TransformerException {
if (args.length != 2) {
System.err.println(“Usage:“);
System.err.println(“ java “ + SimpleJAXP.class.getName()
+ “ xmlFileName xsltFileName“);
System.exit(1);
}

File xmlFile = new File(args[0]);
File xsltFile = new File(args[1]);
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
Result result = new StreamResult(new File(“result.html”));
// create an instance of TransformerFactory
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, result);
}

}

 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:25007次
    • 积分:345
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:14篇
    • 译文:0篇
    • 评论:1条
    文章分类
    文章存档
    最新评论