如何马歇尔使用JAXB一个字符串,有时包含XML内容,有时不
1个回答
2016-01-03
展开全部
String xml="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><student><classRoom><className>计算机</className><id>1</id></classRoom><id>1</id><username>zhangsan</username></student>";
JAXBContext ctx=JAXBContext.newInstance(Student.class);
Unmarshaller um=ctx.createUnmarshaller();
Student stu=(Student)um.unmarshal(new StringReader(xml));
System.out.println(stu.getClassRoom().getClassName());
JAXBContext ctx=JAXBContext.newInstance(Student.class);
Unmarshaller um=ctx.createUnmarshaller();
Student stu=(Student)um.unmarshal(new StringReader(xml));
System.out.println(stu.getClassRoom().getClassName());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询