我有这个例外:unexpected element (uri:"", local:"Fid1Instruments"). Expected elements are <{http://proba.org/proba}Fid1Instruments>

我有package-info.java文件:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://proba.org/proba")
package com.enum1.instruments;


在主要课程中,我这样做:

JAXBContext jx = JAXBContext.newInstance(Fid1Instruments.class);
Unmarshaller u = jx.createUnmarshaller();
JAXBElement<?>  ue= (JAXBElement<?>) u.unmarshal(new File("ex1.xml"));


在生成的java文件中:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "fid1Bond"
})
@XmlRootElement(name = "Fid1Instruments", namespace="http://proba.org/proba")


我阅读了相同问题的答案,但它们不起作用。

最佳答案

根据您的映射,JAXB希望您的文档如下所示,其中元素Fid1Instruments由名称空间http://proba.org/proba限定。

<ns:Fid1Instruments xmlns:ns="http://proba.org/proba">
    ...
</ns:Fid1Instruments>


而您当前正在通过它:

<Fid1Instruments>
    ...
</Fid1Instruments>


了解更多信息


http://blog.bdoughan.com/2010/08/jaxb-namespaces.html

关于java - 意外元素(uri:“”,本地:“Fid1Instruments”)。预期的元素是<{http://proba.org/proba} Fid1Instruments>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20073125/

10-10 09:40