gpt4 book ai didi

java - 如何通过jaxb bindings.xml区分重复元素

转载 作者:行者123 更新时间:2023-12-01 10:29:05 24 4
gpt4 key购买 nike

我必须处理 xsd 模式才能通过 jaxb 生成 java 代码,并且其中一个序列中有两个具有相同名称的元素。这引起了麻烦,我开始使用 Bindings.xml 来区分这两个元素。

我的问题是,我无法为此目的精确定位一个元素,它的目标是我想要的元素加上另一个 compleType 中的另一个元素。

    <?xml version="1.0" encoding="UTF-8"?> 
<xs:schema
xmlns="urn:IETF:metadata:2005:FLUTE:FDT"
xmlns:fl="urn:IETF:metadata:2005:FLUTE:FDT"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mbms2005="urn:3GPP:metadata:2005:MBMS:FLUTE:FDT"
xmlns:mbms2007="urn:3GPP:metadata:2007:MBMS:FLUTE:FDT"
xmlns:mbms2008="urn:3GPP:metadata:2008:MBMS:FLUTE:FDT_ext"
xmlns:mbms2009="urn:3GPP:metadata:2009:MBMS:FLUTE:FDT_ext"
xmlns:mbms2012="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
xmlns:sv="urn:3gpp:metadata:2009:MBMS:schemaVersion"
targetNamespace="urn:IETF:metadata:2005:FLUTE:FDT"
elementFormDefault="qualified"
version="2">
<xs:import namespace="urn:3GPP:metadata:2005:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2005-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2007:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2007-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2008:MBMS:FLUTE:FDT_ext"
schemaLocation="FLUTE-FDT-3GPP-2008-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2009:MBMS:FLUTE:FDT_ext"
schemaLocation="FLUTE-FDT-3GPP-2009-Extensions.xsd"/>
<xs:import namespace="urn:3GPP:metadata:2012:MBMS:FLUTE:FDT"
schemaLocation="FLUTE-FDT-3GPP-2012-Extensions.xsd"/>
<xs:import namespace="urn:3gpp:metadata:2009:MBMS:schemaVersion"
schemaLocation="schema-version.xsd"/>
<xs:element name="FDT-Instance" type="FDT-InstanceType"/>
<xs:complexType name="FDT-InstanceType">
<xs:sequence>
<xs:element name="File" type="FileType" maxOccurs="unbounded"/>
<xs:element ref="sv:schemaVersion"/>
<xs:element ref="mbms2012:Base-URL-1" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="mbms2012:Base-URL-2" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="sv:delimiter"/>
<xs:any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Group" type="mbms2005:groupIdType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="MBMS-Session-Identity-Expiry" type="mbms2005:MBMS-Session-Identity-Expiry-Type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Expires" type="xs:string" use="required"/>
<xs:attribute name="Complete" type="xs:boolean" use="optional"/>
<xs:attribute name="Content-Type" type="xs:string" use="optional"/>
<xs:attribute name="Content-Encoding" type="xs:string" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Encoding-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Instance-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Maximum-Source-Block-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Encoding-Symbol-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Max-Number-of-Encoding-Symbols" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Scheme-Specific-Info" type="xs:base64Binary" use="optional"/>
<xs:attribute ref="mbms2008:FullFDT" use="optional" default="false"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
<xs:complexType name="FileType">
<xs:sequence>
<xs:element ref="mbms2007:Cache-Control" minOccurs="0"/>
<xs:element ref="sv:delimiter"/>
<xs:element ref="mbms2012:Alternate-Content-Location-1" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="mbms2012:Alternate-Content-Location-2" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="sv:delimiter"/>
<xs:any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Group" type="mbms2005:groupIdType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="MBMS-Session-Identity" type="mbms2005:MBMS-Session-Identity-Type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Content-Location" type="xs:anyURI" use="required"/>
<xs:attribute name="TOI" type="xs:positiveInteger" use="required"/>
<xs:attribute name="Content-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="Transfer-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="Content-Type" type="xs:string" use="optional"/>
<xs:attribute name="Content-Encoding" type="xs:string" use="optional"/>
<xs:attribute name="Content-MD5" type="xs:base64Binary" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Encoding-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-FEC-Instance-ID" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Maximum-Source-Block-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Encoding-Symbol-Length" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Max-Number-of-Encoding-Symbols" type="xs:unsignedLong" use="optional"/>
<xs:attribute name="FEC-OTI-Scheme-Specific-Info" type="xs:base64Binary" use="optional"/>
<xs:attribute ref="mbms2009:Decryption-KEY-URI" use="optional"/>
<xs:attribute ref="mbms2012:FEC-Redundancy-Level" use="optional"/>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:schema>

这是我的绑定(bind).xml

<jxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="FLUTE-FDT-3GPP-2005-Extensions.xsd" node="/xsd:schema">
<jxb:bindings node="//xsd:complexType[@name='MBMS-Session-Identity-Expiry-Type']">
<jxb:bindings node=".//xsd:attribute[@name='value']">
<jxb:property name="requiredValue"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="mbms-flute-release11.xsd" node="/xs:schema">
<jxb:bindings node="//xs:complexType[@name='FileType']">
<jxb:bindings multiple="true" node="//xs:element[2]">
<jxb:property name="delimiter1"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

因此,第一个 delimiter 元素正确重命名为 delimiter1,但 schemaVersion 元素也重命名为 delimiter1!

对哪里出了问题有什么建议吗?

编辑 1

按照我的 bindings.xml 的建议使用 @ref 后,如下所示:

<jxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="FLUTE-FDT-3GPP-2005-Extensions.xsd" node="/xsd:schema">
<jxb:bindings node="//xsd:complexType[@name='MBMS-Session-Identity-Expiry-Type']">
<jxb:bindings node=".//xsd:attribute[@name='value']">
<jxb:property name="requiredValue"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="mbms-flute-release11.xsd" node="/xs:schema">
<jxb:bindings node="//xs:complexType[@name='FileType']">
<jxb:bindings multiple="true" node="//xs:element[@ref='sv:delimiter'][1]">
<jxb:property name="delimiter1"/>
</jxb:bindings>
<jxb:bindings node="//xs:element[@ref='sv:delimiter'][2]">
<jxb:property name="delimiter2"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

现在,它会重命名所有出现的 sv:delimiter(文档中的 3),而不是仅重命名 FileType 复杂类型中的那些。它比以前更好,但我希望能够只重命名选定的元素,而不是全部(如果可能的话)。

解决方案

感谢 Xstian,这是有效的解决方案:

<jxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="FLUTE-FDT-3GPP-2005-Extensions.xsd" node="/xsd:schema">
<jxb:bindings node="//xsd:complexType[@name='MBMS-Session-Identity-Expiry-Type']">
<jxb:bindings node=".//xsd:attribute[@name='value']">
<jxb:property name="requiredValue"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
<jxb:bindings schemaLocation="mbms-flute-release11.xsd" node="/xs:schema">
<jxb:bindings node="//xs:complexType[@name='FileType']//xs:element[@ref='sv:delimiter'][1]">
<jxb:property name="delimiter1"/>
</jxb:bindings>
<jxb:bindings node="//xs:complexType[@name='FileType']//xs:element[@ref='sv:delimiter'][2]">
<jxb:property name="delimiter2"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

谢谢

最佳答案

尝试使用示例

<jxb:bindings schemaLocation="mbms-flute-release11.xsd" node="/xs:schema">
<jxb:bindings node="//xs:complexType[@name='FileType']">
<jxb:bindings node="//xs:element[@ref='mbms2012:Alternate-Content-Location-1']">
<jxb:property name="delimiter1"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

<jxb:bindings schemaLocation="mbms-flute-release11.xsd" node="/xs:schema">
<jxb:bindings node="//xs:complexType[@name='FileType']//xs:element[@ref='mbms2012:Alternate-Content-Location-1']">
<jxb:property name="delimiter1"/>
</jxb:bindings>
</jxb:bindings>

关于java - 如何通过jaxb bindings.xml区分重复元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35196342/

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