日期:2014-05-19 浏览次数:20675 次
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();