gpt4 book ai didi

java - JiBX 生成忽略属性命名空间的绑定(bind)

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:47 25 4
gpt4 key购买 nike

我有以下架构(片段):

<xs:complexType name="partnerPaymentsItemType">
<xs:sequence>
<xs:element name="changeTime" type="dateTime"/>
<xs:element name="statusId" type="shortId"/>
<xs:element name="paymentPointId" type="shortString"/>
<xs:element name="money" type="currency"/>
<xs:element name="paymentDestination" type="shortString"/>
<xs:element name="paymentDestinationType" type="shortId"/>
<xs:element name="subagentId" type="shortId" minOccurs="0"/>
<xs:element name="discountCardNumber" type="xs:string" minOccurs="0"/>
<xs:element name="amountAll" type="currency" minOccurs="0"/>
<xs:element name="rewardPercent" type="percentAmount" minOccurs="0"/>
<xs:element name="rewardPercentValue" type="percentAmount" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="paymentTime" use="required" type="dateTime"/>
<xs:attribute name="externalId" use="required" type="id"/>
<xs:attribute name="registeredId" use="required" type="id"/>
</xs:complexType>

我使用 JibX Codegen 工具从中生成源代码,然后编译绑定(bind),这应该允许我将 XML 解码为 Java 对象。这是我的代码生成设置:

<schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
delete-annotations="true"
prefer-inline="false"
generate-all="true"
show-schema="true"
type-substitutions="xs:date xs:string"
package="here.lays.my.package">
<class-decorator class="org.jibx.schema.codegen.extend.SerializableDecorator"/>
</schema-set>

后来,我尝试解析一个 XML 文档,该文档具有标签和属性的命名空间前缀,这导致出现异常

Missing required attribute "paymentTime"

通过 JiBX 源代码进行调试表明,它尝试在文档中查找没有命名空间且名称为“paymentTime”的属性,而文档具有将命名空间映射到 URL 的属性,当然无法找到它。

我已经用 JAD 反编译了绑定(bind),它搜索具有 null 命名空间的属性:

public static PartnerPaymentsItemType JiBX_beeline_binding_unmarshalAttr_1_93(PartnerPaymentsItemType arg1, UnmarshallingContext arg2)
throws JiBXException
{
arg2.pushTrackedObject(arg1);
arg1;
arg1.setPaymentTime(arg2.attributeText(null, "paymentTime"));
arg1.setExternalId(Utility.parseLong(WhitespaceConversions.trim(arg2.attributeText(null, "externalId"))));
arg1.setRegisteredId(Utility.parseLong(WhitespaceConversions.trim(arg2.attributeText(null, "registeredId"))));
arg2.popObject();
return arg1;
}

我将不胜感激任何有助于解决问题的建议 - 例如,为什么 JiBX 生成这样的映射,如何使其尊重属性 namespace ,等等。

最佳答案

JiBX 行为实际上是正确的,属性的命名空间前缀并非基于 xsd。

实际的解决方案是用 XJC/JAXB 替换 JiBX,并为需要属性命名空间前缀的实体提供单独的架构。

关于java - JiBX 生成忽略属性命名空间的绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31806779/

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