如何通过jaxb bindings.xml来区分重复的元素 [英] How to differenciate duplicate elements through jaxb bindings.xml
问题描述
我的问题是,我无法设法定位一个单一的元素为此目的,它是针对我想要的元素加另一个compleType的另一个元素。
<?xml version =1.0encoding = 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:元数据: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-Instancetype =FDT-InstanceType/>
< xs:complexType name =FDT-InstanceType>
< xs:sequence>
< xs:element name =Filetype =FileTypemaxOccurs =unbounded/>
< xs:element ref =sv:schemaVersion/>
< xs:element ref =mbms2012:Base-URL-1minOccurs =0maxOccurs =unbounded/>
< xs:element ref =mbms2012:Base-URL-2minOccurs =0maxOccurs =unbounded/>
< xs:element ref =sv:delimiter/>
< xs:any namespace =## otherprocessContents =skipminOccurs =0maxOccurs =unbounded/>
< xs:element name =Grouptype =mbms2005:groupIdTypeminOccurs =0maxOccurs =unbounded/>
< xs:element name =MBMS-Session-Identity-Expirytype =mbms2005:MBMS-Session-Identity-Expiry-TypeminOccurs =0maxOccurs =unbounded/>
< / xs:sequence>
< xs:attribute name =Expirestype =xs:stringuse =required/>
< xs:attribute name =Completetype =xs:booleanuse =optional/>
< xs:attribute name =Content-Typetype =xs:stringuse =optional/>
< xs:attribute name =Content-Encodingtype =xs:stringuse =optional/>
< xs:attribute name =FEC-OTI-FEC-Encoding-IDtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-FEC-Instance-IDtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Maximum-Source-Block-Lengthtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Encoding-Symbol-Lengthtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Max-Number-of-Encoding-Symbolstype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Scheme-Specific-Infotype =xs:base64Binaryuse =optional/>
< xs:attribute ref =mbms2008:FullFDTuse =optionaldefault =false/>
< xs:anyAttribute processContents =skip/>
< / xs:complexType>
< xs:complexType name =FileType>
< xs:sequence>
< xs:element ref =mbms2007:Cache-ControlminOccurs =0/>
< xs:element ref =sv:delimiter/>
< xs:element ref =mbms2012:Alternate-Content-Location-1minOccurs =0maxOccurs =unbounded/>
< xs:element ref =mbms2012:Alternate-Content-Location-2minOccurs =0maxOccurs =unbounded/>
< xs:element ref =sv:delimiter/>
< xs:any namespace =## otherprocessContents =skipminOccurs =0maxOccurs =unbounded/>
< xs:element name =Grouptype =mbms2005:groupIdTypeminOccurs =0maxOccurs =unbounded/>
< xs:element name =MBMS-Session-Identitytype =mbms2005:MBMS-Session-Identity-TypeminOccurs =0maxOccurs =unbounded/>
< / xs:sequence>
< xs:attribute name =Content-Locationtype =xs:anyURIuse =required/>
< xs:attribute name =TOItype =xs:positiveIntegeruse =required/>
< xs:attribute name =Content-Lengthtype =xs:unsignedLonguse =optional/>
< xs:attribute name =Transfer-Lengthtype =xs:unsignedLonguse =optional/>
< xs:attribute name =Content-Typetype =xs:stringuse =optional/>
< xs:attribute name =Content-Encodingtype =xs:stringuse =optional/>
< xs:attribute name =Content-MD5type =xs:base64Binaryuse =optional/>
< xs:attribute name =FEC-OTI-FEC-Encoding-IDtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-FEC-Instance-IDtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Maximum-Source-Block-Lengthtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Encoding-Symbol-Lengthtype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Max-Number-of-Encoding-Symbolstype =xs:unsignedLonguse =optional/>
< xs:attribute name =FEC-OTI-Scheme-Specific-Infotype =xs:base64Binaryuse =optional/>
< xs:attribute ref =mbms2009:Decryption-KEY-URIuse =optional/>
< xs:attribute ref =mbms2012:FEC-Redundancy-Leveluse =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.xsdnode =/ 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.xsdnode =/ xs:schema>
< jxb:bindings node =// xs:complexType [@ name ='FileType']>
< jxb:bindings multiple =truenode =// xs:element [2]>
< jxb:property name =delimiter1/>
< / jxb:bindings>
< / jxb:bindings>
< / jxb:bindings>
因此,分隔符元素正确地重命名为delimiter1,但是schemaVersion元素也被重命名为delimiter1!
有什么建议吗?
编辑1
根据我的建议,使用 @ref
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.xsdnode =/ 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.xsdnode =/ xs:schema>
< jxb:bindings node =// xs:complexType [@ name ='FileType']>
< jxb:bindings multiple =truenode =// 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.xsdnode =/ 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.xsdnode =/ 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节点= / XS:模式 >
< 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.xsdnode =/ 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>
I have to deal with an xsd schema to generate the java code through jaxb and there is two elements withe same name in one of the sequence. This is causing troubles and i have come to use bindings.xml to differrenciate both elements.
My problem is that i can not manage to pinpoint one single element for this purpose, it is targetting the element i want plus another element from another 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>
Here is my 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>
As a result, the first delimiter element is correctly renamed to delimiter1, but the schemaVersion element is also renamed to delimiter1!
Any suggestion on what is wrong?
EDIT 1
After using @ref
as suggested by my bindings.xml looks like this :
<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>
Now it renames all occurernces of sv:delimiter
(3 in the document) instead of only those within FileType complexe type.
It is better than before but i'd like to be able to only rename selected elements not all if possible.
Solution
Thanks to Xstian, this is the solution that is working :
<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>
Thanks
Try to use for example
<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>
or
<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>
这篇关于如何通过jaxb bindings.xml来区分重复的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!