我正确获得了 html 文件,但在该 html 中,我需要在 html 标签打开后添加元字符集="UTF-8"。我如何通过 java 在运行时执行此操作
我使用以下 java 代码通过 xsl 将 xml 转换为 html
public class TransInfoHtml
{
public static void main(String args[])
{
try {
TransformerFactory tFactory=TransformerFactory.newInstance();
Source xslDoc=new StreamSource("/home/dev702/Desktop/cadgraf-sample-xsl/CadgrafNITF.xsl");
Source xmlDoc=new StreamSource("/home/dev702/Desktop/cadgraf-sample-xsl/Cadgraf_NITF.xml");
String outputFileName="/home/dev702/Desktop/cadgraf-sample-xsl/cadgraf.html";
OutputStream htmlFile=new FileOutputStream(outputFileName);
Transformer trasform=tFactory.newTransformer(xslDoc);
trasform.transform(xmlDoc, new StreamResult(htmlFile));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (TransformerConfigurationException e)
{
e.printStackTrace();
}
catch (TransformerFactoryConfigurationError e)
{
e.printStackTrace();
}
catch (TransformerException e)
{
e.printStackTrace();
}
}
}
为什么要
在运行时这样做?为什么不将其作为输出的一部分添加到 XSLT 模板中?