Using JAXB to manipulate the transformation between Java and XML is very simple, as you can see in an example.
//javabean-->xml@Test Public void test1() {Try{Jaxbcontext Jaxbcontext = jaxbcontext.newinstance (User.class); Marshaller Marshaller = Jaxbcontext.createmarshaller (); User user1 =NewUser ("Zhang San","Zhangsan",123); Marshaller.marshal (User1, System. out); }Catch(Jaxbexception e) {E.printstacktrace (); } }//xml-->javabean@Test Public void test2() {Try{String XML ="<user><money>123</money>"+"<password>zhangsan</password><username> Zhang San </username>"+"</user>"; Jaxbcontext Jaxbcontext = jaxbcontext.newinstance (User.class); Unmarshaller um = Jaxbcontext.createunmarshaller (); User user = (user) Um.unmarshal (NewStringReader (XML)); System. out. println (User.getusername () +","+ User.getmoney ()); }Catch(Jaxbexception e) {E.printstacktrace (); } }
Using JAXB to convert between Java and XML