javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" Group") [英] javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Group")
本文介绍了javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" Group")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.xml只包含数据。
Group class has no any annotation and group.xml just contains data.
可能是什么原因?
推荐答案
看起来你的XML文档有根元素集团而不是集团。您可以:
It looks like your XML document has the root element "Group" instead of "group". You can:
- 将XML上的根元素更改为group
- 添加注释@XmlRootElement(name =Group)到Group类。
这篇关于javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" Group")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文