天天看點

JAXB簡介

介紹

JAXB(Java Architecture for XML Binding)是業界的一個XML綁定JavaBean的标準。它可以根據xml文檔生成Java類,也可以反過來根據Java類生成xml文檔。

入門

JAXBContext context = JAXBContext.newInstance(Autotest.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
autotest = (Autotest) unmarshaller.unmarshal(new ByteArrayInputStream(doc.asXML().getBytes()));

ByteArrayOutputStream dataSourceByteOut = new ByteArrayOutputStream();
context.createMarshaller().marshal(dataSources, dataSourceByteOut);
[/codesyntax]