javax.xml.bind.UnmarshalException:意外的元素。我错过了什么? [英] javax.xml.bind.UnmarshalException: Unexpected element. What am i missing?

查看:1319
本文介绍了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:意外的元素OrderHistory。预期的元素是{_http://orderhistory.shc.com/common/domain} OrderHistory。但是我检查了我的OrderHistory.java我有

I am getting javax.xml.bind.UnmarshalException: Unexpected element "OrderHistory". Expected elements are "{_http://orderhistory.shc.com/common/domain}OrderHistory". but i checked my OrderHistory.java i have the

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

我缺少什么???

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

Even the package-info.java file is also present

这是我的回复xml,

<?xml version =1.0encoding =UTF-8?>

< OrderHistory>

< guid> 5555< / guid> ;

< syNumber xsi:nil =true>< / syNumber>

< email xsi:nil =true>< / email>

< totalPages> 0< / totalPages>

< / OrderHistory>

Here is my response 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>

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

Still i am facing the same issue???

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

I ve made changes to my package-info.java i have removed the namespace attribute but still i am seeing the same issue,

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

推荐答案

看起来您的输入文档不符合命名空间。

It appears as though your input document is not namespace qualified.

您有:

<OrderHistory>...</OrderHistory>

您的JAXB(JSR-222)实现期待:

And your JAXB (JSR-222) implementation is expecting:

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

相关

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

If you are unmarshalling from a DOM, make sure to call setNamespaceAware(true) on the instance of DocumentBuilderFactory.

更多信息

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

这篇关于javax.xml.bind.UnmarshalException:意外的元素。我错过了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆