document.addContent(new ProcessingStruction("xml-stylesheet","type='text/xsl' href='treefunc.xsl'")hope it will help you.But I think you can use JAXP to transform xml with xsl
解决方案 »
- 这段代码的输出很让我困惑,求高手解释下(关于StringBuffer)
- java如何发送事件
- 请教toCharArray()函数
- log4j中的方法
- 11月16日-基于Java的企业级Web开发技术
- javascript的优化问题。急!!!
- 菜鸟,求救!请问GUI的高手,你们大多代码是手写还是生成的?
- 问哪有JFC核心编程(第二版)(清华大学出版社)的光盘下载啊!
- ★★★★★极度郁闷中,利用eclipse内置的cvs进行基于CVS的团队开发中,遇到问题,高人指点,解决了再开贴给300分★★★★★
- 不支持java.io.Serializable接口的对象能否通过writeObject方法写入流中?
- weblogic里难道只能调用一个.jsp,其它就不行了吗,郁闷。
- 编译数据库连接池出错,不知什么原因,请大家帮忙看看,谢谢发,急!!
Node sheet = doc.createProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"'treefunc.xsl\"");
Element root = new Element("root");
doc.setRootElement(root);
ProcessingInstruction pi = new ProcessingInstruction("stylesheet", "");
pi.setValue("type", "text/xsl");
pi.setValue("href", "treefunc.xsl");
doc.addContent(pi);
XMLOutputter outputter = new XMLOutputter(" ", true);
outputter.output(doc, System.out);
编译不过去呀
<?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"?>请指点!
{
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 produceNewXml()
{
try
{
org.jdom.input.SAXBuilder sb = new org.jdom.input.SAXBuilder();
org.jdom.Document doc = sb.build(new java.io.
StringBufferInputStream(xmlContent)); org.jdom.Document doc2 = new org.jdom.Document(); 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 addCommentXml()
{
try
{
org.jdom.input.SAXBuilder sb = new org.jdom.input.SAXBuilder();
org.jdom.Document doc = sb.build(new java.io.
StringBufferInputStream(xmlContent)); org.jdom.Document doc2 = new org.jdom.Document(); 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));
org.jdom.Comment comment = new org.jdom.Comment(" add three instruction!");
doc.addContent(comment);
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 | org.jdom.filter.ContentFilter.COMMENT); 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();
// addCommentXml();
}
}