JAXB is used for mapping xml to java classes.
To generate java class from xml we use xjc.
Command: xjc -d sourcefolder schema.
Tip: Do not try to use parameter: -p in command line. This will make all class in the same package.
It results in namespace will be removed because of JAXB optimization. I've got a problem because it.
Unmarshalling:
JAXBContext context = JAXBContext.newInstance("enter generated packagename here");
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.unmarshal(new FileInputStream(fileName));
Marshalling:
JAXBContext context = JAXBContext.newInstance("enter generated packagename here");
JAXBElement root = soapFactory.createEnvelope(rootElement);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(root, System.out);
Friday, July 13, 2007
JAXB tutorial and tip
Posted by CABA LAM at 6:40 PM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment