gpt4 book ai didi

javax.xml.bind.UnmarshalException : Unexpected element. 我缺少什么?

转载 作者:行者123 更新时间:2023-11-30 04:41:55 25 4
gpt4 key购买 nike

我正在做这个,

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".但我检查了我的 OrderHistory.java 我有

@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)

了解更多信息

关于javax.xml.bind.UnmarshalException : Unexpected element. 我缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12079052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com