我正在尝试运行此代码:
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Tags tags = (Tags) unmarshaller.unmarshal(new File("Tags.xml"));
然而,我收到此错误:
javax.xml.bind.UnmarshalException:意外元素(uri:"",local:" tags")。预期的元素是(无)
如何防止发生此异常?这是我的根本要素:
@XmlRootElement(name = "tags")
答案 0 :(得分:1)
JAXB不知道应该处理哪些类。
JAXBContext jaxbContext = JAXBContext.newInstance(Tags.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Tags tags = (Tags) unmarshaller.unmarshal(new File("Tags.xml"));