JAXB
Advantages:
- Sun's Implementation
- well known with JAX-WS & JAX-RPC
- To Marshall & UnMarshall we to write manual code.
Advantages:
- No need to write code to Marshall & UnMarshall
- Inbuilt support for Saxon xQuery & XPath
- All Bea products using (Weblogic Portal, Aqualogic Service Bus)
- Not known by many developers
public class Main {
public static void main(String[] args) {
Object pud = unmarshall(some.pkg", TestDocument.class);
marshall("poc.act.cms.poc", pud);
}
public static void marshall(String namesapce, Object object) {
try {
JAXBContext jc = JAXBContext.newInstance(namesapce);
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(object, System.out);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object unmarshall(String namesapce, Object object) {
try {
JAXBContext jc = JAXBContext.newInstance(namesapce);
Unmarshaller m = jc.createUnmarshaller();
return m.unmarshal(new File("xmlfile.xml"));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
public class Main {
public static void main(String[] args) {
try {
TestDocument pud = TestDocument.Factory.parse(new File("xmlfile.xml"));
System.out.println(pud); // this will print as string
} catch (XmlException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
as you seen by code itself XmlBean is very small.
Here is report from netbeans profiler for both JAXB & Xmlbeans to parse 10,000 rows XML file. JAXB taken 30+ seconds, where XmlBeans taken 17+ seconds.
Xmlbeans
JAXB
Comments
Post a Comment