Java中进行xslt转换的示例代码
来源:互联网 发布:ubuntu 安装libxml 编辑:程序博客网 时间:2024/05/16 03:31
package blog.csdn.net.arui;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class BasicXsl ...{
/** *//**
* This method applies the xsl file to in file, and writes the output to out
* file.
*
* @param inFilename
* in file path
* @param outFilename
* out file path
* @param xslFilename
* xsl file path
*/
public static void xsl(
String inFilename,
String outFilename,
String xslFilename) ...{
try ...{
// Create transformer factory
TransformerFactory factory = TransformerFactory.newInstance();
// Use the factory to create a template containing the xsl file
Templates template = factory.newTemplates(new StreamSource(
new FileInputStream(xslFilename)));
// Use the template to create a transformer
Transformer xformer = template.newTransformer();
// Prepare the input and output files
Source source = new StreamSource(new FileInputStream(inFilename));
Result result = new StreamResult(new FileOutputStream(outFilename));
// Apply the xsl file to the source file and write the result to the
// output file
xformer.transform(source, result);
} catch (FileNotFoundException e) ...{
// File not found
} catch (TransformerConfigurationException e) ...{
// An error occurred in the XSL file
} catch (TransformerException e) ...{
// An error occurred while applying the XSL file
// Get location of error in input file
}
}
}
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class BasicXsl ...{
/** *//**
* This method applies the xsl file to in file, and writes the output to out
* file.
*
* @param inFilename
* in file path
* @param outFilename
* out file path
* @param xslFilename
* xsl file path
*/
public static void xsl(
String inFilename,
String outFilename,
String xslFilename) ...{
try ...{
// Create transformer factory
TransformerFactory factory = TransformerFactory.newInstance();
// Use the factory to create a template containing the xsl file
Templates template = factory.newTemplates(new StreamSource(
new FileInputStream(xslFilename)));
// Use the template to create a transformer
Transformer xformer = template.newTransformer();
// Prepare the input and output files
Source source = new StreamSource(new FileInputStream(inFilename));
Result result = new StreamResult(new FileOutputStream(outFilename));
// Apply the xsl file to the source file and write the result to the
// output file
xformer.transform(source, result);
} catch (FileNotFoundException e) ...{
// File not found
} catch (TransformerConfigurationException e) ...{
// An error occurred in the XSL file
} catch (TransformerException e) ...{
// An error occurred while applying the XSL file
// Get location of error in input file
}
}
}
- Java中进行xslt转换的示例代码
- Java中XSLT转换的简单实例
- JAVA利用XSLT进行格式转换,XML转成自己需要的XML、HTML等。
- XSLT语法 在.net中使用XSLT转换xml文档示例
- jaxp实现xslt转换示例
- Java中对List集合内的元素进行顺序、倒序、随机排序的示例代码
- Java中对List集合内的元素进行顺序、倒序、随机排序的示例代码
- XSLT的转换机制
- 一段XSLT转换XML节点名的测试代码
- 用Java进行HTTP请求的代码示例
- 在java代码中进行px与dip(dp)、px与sp单位值的转换
- 在java代码中,用xslt处理xml文件
- 在java代码中,用xslt处理xml文件
- JAVA与JSON的使用方式及转换示例代码
- 应用XSLT进行菜单呈现转换
- 通过XSLT访问Java代码
- [代码生成] 使用Java与XSLT的10条技巧
- Java中使用SSHA对数据进行加密的示例
- A story for anyone who with an appetite for LOVE!
- 打造メンアットワーク!魔兽学院men at work2《永远的羁绊》 中文终极版(刺杀事件、H补丁)
- 注册表解锁的方法
- 实现自绘菜单
- 实训C++语言设计——3*3矩阵转置函数
- Java中进行xslt转换的示例代码
- NetBeans IDE 6.0.1 多国语言版下载地址
- 实训C++语言设计——两个字符串的连接
- Visual Studio 2005提示"试图运行项目时出错:无法启动调试。绑定句柄无效"的解决
- JAVA的基础知识(给自己看的笔记)。
- 实训C++语言设计——定义一个类
- 台湾同胞口中PHP的一些名词
- PHP中双引号和单引号的区别
- 实训C++语言设计——继承与派生