Unmarshaller异常javax.xml.bind.UnmarshalException: unexpected element处理方法
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element

·
在marshaller/Unmarshaller开发过程中可能会遇到javax.xml.bind.UnmarshalException: unexpected element异常,比如
unexpected element (uri:"", local:"Group"). Expected elements are <{}group>
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"));
通常的解决方法是:
- Change the root element on your XML to be "group"
- Add the annotation @XmlRootElement(name="Group") to the Group classs.
但有时这样做了,还是不能解决问题。原因在于ObjectFactory类。
在开发的过程中我们可能是根据XSD文件(XML文件的格式文件),通过JDK的/bin/xjc.exe生成java文件。有些时候我们会手工修改生成后的java文件;有些时候XSD文件会有冲突,我们会删除冲突的文件,分别生成java文件,这样就导致了xjc生成的ObjectFactory.java中没有包含全部的与XSD文件对应的方法。所以在删除冲突的XSD文件,分别生成java文件以后,要手动修改ObjectFactory.java,使之包含所有生成的java类的createXXX()方法。这样再编译打包,重现运行,就不会出现javax.xml.bind.UnmarshalException: unexpected element异常了。




A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:19 天前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
更多推荐
所有评论(0)