JAXB marshling,jaxbmarshling,public class
分享于 点击 37104 次 点评:99
JAXB marshling,jaxbmarshling,public class
public class Play { public static void generateXML(Object rootElement, Writer writer) throws JAXBException { if (rootElement == null) throw new IllegalArgumentException("rootElement is null"); if (writer == null) throw new IllegalArgumentException("writer is null"); JAXBContext context = JAXBContext.newInstance(rootElement.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(rootElement, writer); } public static void main(String[] args) throws JAXBException { final StringWriter writer = new StringWriter(); generateXML(new AnnotatedClass(), writer); System.out.println( writer.getBuffer().toString()); }}//该片段来自于http://byrx.net
用户点评