当前位置: 代码迷 >> J2EE >> 由xsd 转换 xml解决办法
  详细解决方案

由xsd 转换 xml解决办法

热度:629   发布时间:2016-04-22 01:51:34.0
由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 markswriter.println("<?xml version='1.0'?>");writer.println("<?xml-stylesheet type=\"text/xsl\" href=\"\">");//create and configure marshaller to leave out processing instructionsMarshaller marshaller = context.createMarshaller();marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);//marshal to the StringWritermarshaller.marshal(someObject,writer);//get the string representation String str = writer.toString();
  相关解决方案