
java中如何用JAXBContext解析XML字符串 注意是字符串
“<?xmlversion=‘1.0’encoding=‘UTF-8’standalone=‘yes’?><customerid="1234"><age>18</age>...
“<?xml version=‘1.0’ encoding=‘UTF-8’ standalone=‘yes’?>
<customer id="1234">
<age>18</age>
<name>sdfsd</name>
</customer>” 展开
<customer id="1234">
<age>18</age>
<name>sdfsd</name>
</customer>” 展开
展开全部
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());
追问
那个实体类的标记配置能不能给下 谢谢哈 大神???
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询