ProcessingInstruction pi = new ProcessingInstruction ("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\""); doc.addContent(pi);
解决方案 »
- 疑问解答,另希望找到一好心的朋友能够指导我!
- Quartz cluster scheduler job not fire
- Eclipse Helios Release 相关插件
- java.io.FileNotFoundException怎么解决?
- 名索网盈利模式是什么
- 求本书 严蔚敏数据结构与抽象(Java语言版)PDF
- 问下java连接oracle10的我问题,急呀呀
- JSF中,<h:dataTable>中<h:commandLink/>点击失效
- 急!!!求高手!!!!!!!在线等!!!!!!!!!!!!!!!!!!!!
- webservice 获取 客户端的 ip??
- 大家看看我的做法好不好?是不是要改进一下
- 如何在xsl中加入top.htm和bottem.htm???急急急--在线等待
ProcessingInstruction pi = new ProcessingInstruction
("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\"");
doc.addContent(pi);
<?xml version="1.0" encoding="UTF-8"?>
<?stylesheet href="treefunc.xsl" type="text/xsl"?>
<root />但用以上的方法出来的都是<?xml version="1.0" encoding="UTF-8"?>
<root />
<?stylesheet href="treefunc.xsl" type="text/xsl"?>请指点!
其实这条指令加在头和尾都一样!都是在根节点之外!
至于为什么JDOM把它加在尾部我也不知道!!没有时间去更深入研究!
{
static String xmlContent;
public static void init()
{
xmlContent = "<?xml version=\"1.0\" encoding=\"GB2312\"?>"
+ "<lib>"
+ "<book>"
+ "<name>Java</name>"
+ "</book>"
+ "<book>"
+ "<name>XML</name>"
+ "<pubdate>2002-10-07</pubdate>"
+ "</book>"
+ "</lib>";
} public static void outputXml()
{
try
{
org.jdom.input.SAXBuilder sb = new org.jdom.input.SAXBuilder();
org.jdom.Document doc = sb.build(new java.io.
StringBufferInputStream(xmlContent));
org.jdom.output.XMLOutputter outer = new org.jdom.output.XMLOutputter();
//<?stylesheet href="treefunc.xsl" type="text/xsl"?>
java.util.Map map = new java.util.HashMap();
map.put("href","treefunc.xsl");
map.put("type","text/xsl");
doc.addContent(new org.jdom.ProcessingInstruction("AA","BB"));
doc.addContent(new org.jdom.ProcessingInstruction("CC","DD"));
doc.addContent(new org.jdom.ProcessingInstruction("stylesheet",map)); java.io.StringWriter sw = new java.io.StringWriter();
org.jdom.filter.ContentFilter piFilter = new org.jdom.filter.ContentFilter(
org.jdom.filter.ContentFilter.PI );
org.jdom.filter.ContentFilter dFilter = new org.jdom.filter.ContentFilter(
org.jdom.filter.ContentFilter.ELEMENT ); outer.output(doc.getContent(piFilter),sw);
outer.output(doc.getContent(dFilter),sw);
sw.close();
System.out.println(sw.toString());
//Debug.printTextAsXml(sw.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
} public static void main(String[] args)
{
init();
outputXml();
}
}