javax.xml.bind.UnmarshalException:意外元素.我错过了什么



我正在做这件事,

JAXBContext jaxbContext = JAXBContext.newInstance(new Class[] { 
      mine.beans.ObjectFactory.class }); 
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
orderhistory = (OrderHistory) unmarshaller.unmarshal(new StreamSource(
      new StringReader(responseXML)));`

我收到了javax.xml.bind.UnmarshalException: Unexpected element "OrderHistory". Expected elements are "{_http://orderhistory.shc.com/common/domain}OrderHistory".,但我查看了我的订单历史。我有

@XmlRootElement(name = "OrderHistory")
public class OrderHistory{

我错过了什么???

即使是package-info.java文件也存在

这是我的响应xml,
<?xml version="1.0" encoding="UTF-8"?>
<OrderHistory>
<guid>5555</guid>
<syNumber xsi:nil="true"></syNumber>
<email xsi:nil="true"></email>
<totalPages>0</totalPages>
</OrderHistory>

我仍然面临着同样的问题???

我已经对我的package-info.java进行了更改,我删除了namespace属性,但我仍然看到了相同的问题,

@javax.xml.bind.annotation.XmlSchema() package mine.beans;

您的输入文档似乎不符合命名空间。

您有:

<OrderHistory>...</OrderHistory>

您所期望的JAXB(JSR-222)实现是:

<OrderHistory xmlns="_http://orderhistory.shc.com/common/domain">...</OrderHistory>

相关

如果要从DOM解组,请确保在DocumentBuilderFactory的实例上调用setNamespaceAware(true)

有关更多信息

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

作为提示。尝试封送对象中的文档,并查看标记是否按预期编写。

您是否尝试修改XML?您的UNmarshaller希望OrderHistory元素是"http://orderhistory.shc.com/common/domain"命名空间,但它不是。你可以尝试一下:

<?xml version="1.0" encoding="UTF-8"?>
<OrderHistory xmlns="_http://orderhistory.shc.com/common/domain">
<guid>5555</guid>
<syNumber xsi:nil="true"></syNumber>
<email xsi:nil="true"></email>
<totalPages>0</totalPages>
</OrderHistory>

相关内容

最新更新