ProcessingInstruction pi = new ProcessingInstruction ("xml-stylesheet","href=\"bookList.html.xsl\" type=\"text/xsl\""); doc.addContent(pi);
解决方案 »
- core java 2第七版193页一句话难道了众多计算机老师
- 一个无状态会话bean可不可以从普通java类继承?抽象java类呢?
- jacorb中如果要启动命名服务是不是ns.bat,问题如下
- 请教通过tomcat的服务器认证,无法用中文当用户名登录的解决方法
- struts+spring+hibernate问题,请教个位大侠
- 30岁前不要再乎的事----不是我说的,呵呵
- Applet在jSP怎么不能显示?高分求救。。。急
- 有劳各位了:)
- 用JBOSS加MYSQL开发CMP遇到的问题!大家帮忙啊!最高加200分
- “双星捧月—WebSphere Studio和Rational助力应用开发”技术研讨会,免费参加!(京、穗)
- 大家看看我的做法好不好?是不是要改进一下
- 如何在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();
}
}