日期:2014-05-19  浏览次数:20634 次

由xsd 转换 xml
怎么在转换的xml那里添加 <?xml-stylesheet type='text/xsl' href='foobar.xsl' ?> 这个? 
现在只能转换生成xml其他结点内容, 但这一句怎么加上去呢?



各位大侠帮帮小弟.

------解决方案--------------------
似乎没有直接的函数可以支持,要换个做法:

Java code

StringWriter writer = new StringWriter();
//add processing instructions "by hand" with escaped quotation marks
//or single marks
writer.println("<?xml version='1.0'?>");
writer.println("<?xml-stylesheet type=\"text/xsl\" href=\"\">");

//create and configure marshaller to leave out processing instructions
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

//marshal to the StringWriter
marshaller.marshal(someObject,writer);
//get the string representation 
String str = writer.toString();