我必须处理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>
这是我的bindings.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>
因此,第一个分隔符元素被正确地重命名为delimiter1,但schemaVersion元素也被重命名为delimiter1!
有关错误的任何建议吗?
按照我的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 complexe类型中的出现。
它比以前更好,但我希望能够只在可能的情况下重命名所选元素。
感谢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>
由于
答案 0 :(得分:1)
尝试使用例如
<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>