欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

JAXB marshling,jaxbmarshling,public class

来源: javaer 分享于  点击 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
相关栏目:

用户点评