javax.xml.bind.UnmarshalException:意外元素(uri:“",本地:“组") [英] javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Group")

查看:34
本文介绍了javax.xml.bind.UnmarshalException:意外元素(uri:“",本地:“组")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

unexpected element (uri:"", local:"Group"). Expected elements are <{}group>

从xml解组时遇到异常

Meet an exception when unmarshalling from xml

JAXBContext jc = JAXBContext.newInstance(Group.class); 
Unmarshaller unmarshaller = jc.createUnmarshaller();
Group group = (User)unmarshaller.unmarshal(new File("group.xml"));

Group 类没有任何注解,group.xml 只包含数据.

Group class has no any annotation and group.xml just contains data.

有什么可能是原因吗?

推荐答案

看起来您的 XML 文档具有根元素Group"而不是group".您可以:

It looks like your XML document has the root element "Group" instead of "group". You can:

  1. 将 XML 上的根元素更改为组"
  2. 将注释@XmlRootElement(name="Group") 添加到 Group 类.

这篇关于javax.xml.bind.UnmarshalException:意外元素(uri:“",本地:“组")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆