jdom生成xml文档时插入处理指令的问题

//生成一条处理指令
Document jdom=new Document(new Element("root"));
ProcessingInstruction pi = new ProcessingInstruction
("xml-stylesheet","type='text/xsl'href='form.xsl'");
jdom.addContent(pi);
可是我为什么总是不能把那行放在root element的前边呢?总是在后边,在后边用IE就不能显示,放到前边就可以了。谢谢。
---------------------------------------------------------------

自己动手封装一下就可以了。

public static void OutputDocToFile(Document doc, String xslpath,
String encoding, String filePath) {
//setup this like outputDocument
try {
XMLOutputter outputter = new XMLOutputter(" ", true, encoding);
FileWriter out = new FileWriter(filePath);
out.write("

1) { //编码的名字至少有一个字符 out.write(" encoding=\"" + encoding + "\""); } out.write("?>"); if (xslpath != null && xslpath.length() > 3) { //xsl 文件的名字至少有三个字符 out.write("

");
}
outputter.output(doc.getRootElement(), out);
out.close();
}
catch (java.io.IOException e) {
e.printStackTrace();
}
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus