【问题标题】:unexpected element (uri:"", local:"Fid1Instruments"). Expected elements are <{http://proba.org/proba}Fid1Instruments>意外元素(uri:“”,本地:“Fid1Instruments”)。预期的元素是 <{http://proba.org/proba}Fid1Instruments>
【发布时间】:2013-11-19 13:41:45
【问题描述】:

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

我有 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")

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

【问题讨论】:

  • 问题可能出在您的ex1.xml 文件中。你也可以发一下吗?

标签: java namespaces jaxb


【解决方案1】:

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

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

而你目前正在通过它:

<Fid1Instruments>
    ...
</Fid1Instruments>

更多信息

【讨论】:

  • 非常感谢,真的很有帮助!!
猜你喜欢
  • 2018-01-10
  • 2013-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-05
  • 2016-07-12
相关资源
最近更新 更多