读取并显示xml问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 05:36:26
在java开发中请求一个url返回一个xml文件,然后通过xslt来解析xml并显示,有什么比较好的常规方法?
另外如果在portlet中呢?如何做?

我们是这么做的:
try {
File xslt = new File("d:\\gsj-zz-001.xslt");
File xml = new File("d:\\gsj-zz-001_9999999999.xml");

javax.xml.transform.Source xmlSource = new StreamSource(
new BufferedReader(new FileReader(xml)));
Transformer trans = null;

Source xslSource = new StreamSource(xslt);

TransformerFactory transFact = TransformerFactory.newInstance();
Templates templates = transFact.newTemplates(xslSource);

trans = templates.newTransformer();
trans.transform(xmlSource, new StreamResult(System.out));
} catch (Exception e) {
e.printStackTrace();
}
portlet没用过