xml和bean之间转化
//bean
@XmlRootElement(name = "register")br/>@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name","age" })
public class User {
private String name;
private String age;
public String getName() {
return name;
}

public void setName(String name) {
    this.name = name;
}

public String getAge() {
    return age;
}

public void setAge(String age) {
    this.age = age;
}

@Override
public String toString() {
    return "User{" +
            "name='" + name + '\'' +
            ", age='" + age + '\'' +
            '}';
}

}br/>bean反序列化xml:
@Test
public void test2(){
try {
User user=new User();
user.setName("zhan");
user.setAge("23");
JAXBContext context = JAXBContext.newInstance(User.class);
Marshaller marshaller = context.createMarshaller();
// 是否格式化
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// 是否省略头文件
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, false);
StringWriter swriter = new StringWriter();
// 将XML内容打印为字符串
marshaller.marshal(user, swriter);

        String xmlString = swriter.getBuffer().toString();
        System.out.println(xmlString);
    }catch (Exception e){
        e.printStackTrace();
    }
}

xml序列化成bean:br/>@Test
public void test3(){
try {
String xml="\n" +
"\n" +
" zhan\n" +
" 23\n" +
"
";
JAXBContext context = JAXBContext.newInstance(User.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Object unmarshal = unmarshaller.unmarshal(new StringReader(xml));
System.out.println(unmarshal.toString());
} catch (JAXBException e) {
e.printStackTrace();
}
}