【发布时间】:2025-12-23 20:35:11
【问题描述】:
为了找出我的 SOAP 服务得到的原因,我进行了多次搜索:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd", local:"Tagrapportering"). Expected elements are <{urn:BVTAF}Tagrapportering>,<{urn:BVTAF}MessageHeader>
当我的网络服务收到这个 xml 时:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MessageArray xmlns="urn:BVTAFMessageInbox">
<BVTagrapportering xmlns="urn:BVTAF">
<MessageHeader><MessageStatus>1</MessageStatus><MessageReference><MessageType MessageTypeCode="0"/><MessageNumber>5572098</MessageNumber><MessageDateTime>2017-10-31T19:56:22.4312743+01:00</MessageDateTime></MessageReference><Sender>10001</Sender><Recipient>10040</Recipient></MessageHeader>
<Tagrapportering xmlns="http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd">
<Tag tagnr="xxxxx" avgangsdatum="2017-10-31" tagslag="RST" dest="M" trafikutovare="Trans...(I intentionally clipped the xml here)
Unmarshaller 固执地说它希望 Tagrapportering 在 urn:BVTAF 命名空间中,但它不在该命名空间中,这是我的 BVTagrapportering 类的开始:
/**
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="MessageHeader" type="{urn:BVTAF}MessageHeader"/>
* <element name="Tagrapportering" type="{http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd}Tagrapportering"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "",
propOrder = {
"messageHeader",
"tagrapportering",
}
)
@XmlRootElement(name = "BVTagrapportering" )
public class BVTagrapportering {
@XmlElement(name = "MessageHeader", namespace = "urn:BVTAF", required = true)
protected MessageHeader messageHeader;
@XmlElement(name = "Tagrapportering", namespace = "http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd", required = true)
protected Tagrapportering tagrapportering;
在我的包中,我有这个 package.info.java:
@javax.xml.bind.annotation.XmlSchema(namespace = "urn:BVTAF",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package bvtaf;
问题是 IF 我从传入的 SOAP 消息中删除了 Tagrapportering 元素中的 xmlns 属性,解组就像一个魅力,但我不控制传入的 SOAP 消息,所以这种方法对我来说不是可行的方法......
我正在使用从 wsdl 到 java 的 Apache CXF 3.2.1 Web 服务代码生成器来生成我的类,并在 Tomcat 8.5 中运行它。
谁能帮帮我!?这让我发疯了......
【问题讨论】:
标签: xml soap xml-parsing cxf unmarshalling