我已经使用.xsd文件生成Java类,并且使用XML文件,我需要解组。JAXB Unmarshall异常 - 意外的元素
我使用这个代码:
JAXBContext objJAXBContext = JAXBContext.newInstance("my.test");
// create an Unmarshaller
Unmarshaller objUnmarshaller = objJAXBContext.createUnmarshaller();
FileInputStream fis = new FileInputStream("test.xml");
JAXBElement<Root> objMyRoot = (JAXBElement<Root>) objUnmarshaller.unmarshal(fis);
Root mRoot = objMyRoot.getValue();
和我收到此错误:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Root"). Expected elements are (none)
我见过很多的解决方案,但没有在我的项目工作。
我可以尝试做什么?
您可以向我们展示test.xml'的'内容开始。 – skaffman 2012-03-02 11:21:29
和xsd文件。 – 2012-03-03 13:17:28