我正在尝试从xml文件创建Java对象。 我正在使用jaxb(解组)创建Java对象。 我遇到了错误javax.xml.bind.UnmarshalException:unexpected element(uri:“http://www.w3.org/2001/XMLSchema”,local:“schema”)。 预期的元素是
我查了一下谷歌,发现我们需要xsd文件才能做到这一点...所以我使用apache inst2xsd工具将其转换为xsd。 我正在使用以下Java代码:
import java.io.FileNotFoundException;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="report")
public class Report
{
public static void main(String [] args) throws FileNotFoundException
{
try
{
JAXBContext jc = JAXBContext.newInstance(new Class[] {com.bcbsks.testjb.Report.class});
Unmarshaller um = jc.createUnmarshaller();
Report myJAXBObject = (Report)um.unmarshal(new java.io.FileInputStream("report.xsd"));
}
catch( UnmarshalException ue )
{
ue.printStackTrace();
}
catch( JAXBException je )
{
je.printStackTrace();
}
}
}
但我遇到了以下错误:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"schema"). Expected elements are (none)
请问我做错了什么?
非常感谢您的帮助。
unmarchal(FileInputStream, Class<T>)
没有方法签名。 - thomas.mc.workObjectMapper
,它也是由xjc创建的:https://dev59.com/Qonca4cB1Zd3GeqP5AZn#31405556 - thomas.mc.work