【发布时间】:2010-10-25 12:25:42
【问题描述】:
目前,我有一个包含 XML 元素的 String 对象:
String carsInGarage = garage.getCars();
我现在想将此字符串作为输入/流源(或某种源)传递,但不确定选择哪一个以及如何实现它。
我看过的大多数解决方案都导入包:javax.xml.transform 并接受 XML 文件 (stylerXML.xml) 并输出到 HTML 文件 (outputFile.html)(参见下面的代码)。
try
{
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("styler.xsl"));
transformer.transform(new StreamSource("stylerXML.xml"), new StreamResult(new FileOutputStream("outputFile.html")));
}
catch (Exception e)
{
e.printStackTrace();
}
我想接受一个字符串对象并输出(使用 XSL)到现有 JSP 页面中的一个元素。我只是不知道如何实现这一点,即使看过上面的代码。
有人可以提供建议/帮助吗?我一直在寻找解决方案,但我就是无法拿出任何东西。
【问题讨论】: