我有一个 xml 文件有效负载,我想使用 jaxb 解组,我创建了一个用于解组的 pojo 类,并且我已经为该 pojo 定义了 xml 属性和元素,但是我对命名空间、如何注释有点困惑他们?
我的 xml 文件:
<ns1:ContractLinkEvent xmlns:ns0="http://Enterprise.BizTalk.Canonical.Schemas/v2.0/ESB" xmlns:ns1="http://Enterprise.BizTalk.MCF.Core.Schemas/v2.0/ESB">
<Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</Header>
<ContractLink xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ContractLinkId>1509148</ContractLinkId>
<BillingProfile>
<BillingProfileId>173886</BillingProfileId>
<BillingProfileCode xsi:nil="true"/>
</BillingProfile>
</ContractLink>
</ns1:ContractLinkEvent>
我的 Jaxb 注释 Pojo 是:
@XmlRootElement(name = "ContractLinkEvent", namespace="http://Enterprise.BizTalk.Canonical.Schemas/v2.0/ESB")
@XmlAccessorType(XmlAccessType.FIELD)
public class ContractLinkPojo {
@XmlElement(name="Header")
private String Header;
@XmlElement(name="ContractLink")
private String ContractLink;
. . . 继续
解组时出现以下异常:
java.io.IOException: javax.xml.bind.UnmarshalException
- with linked exception:
[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 1; unexpected element (uri:"http://Enterprise.BizTalk.MCF.Core.Schemas/v2.0/ESB", local:"ContractLinkEvent"). Expected elements are (none)]
我认为我没有正确定义命名空间,因为我还没有定义命名空间,因为我仍然感到困惑,有什么想法吗?
编辑: 这是我的解组路由
rest("/readXml")
.consumes("application/xml")
.post()
.to("direct:xmlread");
from("direct:xmlread").streamCaching()
.doTry().unmarshal(xmlDataFormat)
.process(readAndInsertXml)
.to("mock:result").end();
}