f



xjb binding with xs:any

Hello,

I try to compile with XJC a XSD schema into Java classesn. The XSD file is:
https://github.com/APTD/Simulation/blob/master/src/main/xsd/network.xsd

and the binding file:
https://github.com/APTD/Simulation/blob/master/src/main/xsd/bindings.xjb

The XSD includes the main schema: http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/railML.xsd

but there a some subschema defined which uses an xs:any attribut. If I try to compile my main XSD, I get the error that Any is defined multiple time (in each subschema). e.g.:

http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/infrastructure.xsd (line 435)

http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/genericRailML.xsd (line 140)

http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/timetable.xsd (line 400)

How can I fix this error within my binding file? In my case the any elements can be skipped / ignored.

Thanks

Phil
0
Philipp
11/29/2016 7:07:07 PM
comp.lang.java.programmer 52714 articles. 0 followers. Post Follow

6 Replies
117 Views

Similar Articles

[PageSpeed] 41

Am 29.11.2016 um 20:07 schrieb Philipp Kraus:
> Hello,
>
> I try to compile with XJC a XSD schema into Java classesn. The XSD file is:
> https://github.com/APTD/Simulation/blob/master/src/main/xsd/network.xsd
>
> and the binding file:
> https://github.com/APTD/Simulation/blob/master/src/main/xsd/bindings.xjb
>
> The XSD includes the main schema: http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/railML.xsd
>
> but there a some subschema defined which uses an xs:any attribut. If I try to compile my main XSD, I get the error that Any is defined multiple time (in each subschema). e.g.:
>
> http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/infrastructure.xsd (line 435)
>
> http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/genericRailML.xsd (line 140)
>
> http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/timetable.xsd (line 400)
>
> How can I fix this error within my binding file? In my case the any elements can be skipped / ignored.
>
> Thanks
>
> Phil
>

Have you tried googling this? Here's a post that might help:
http://stackoverflow.com/questions/13610217/jaxb-compiling-issue-error-property-any-is-already-defined

I'm guessing the problem is caused by namespace="##other" occurring in 
each sub-schema (although they do seem to share the same target 
namespace, so it is a bit strange.) Have you made sure that the files 
define mutually exclusive sets of types?

Perhaps adding processContents="skip" in the schemas would help (see 
https://jaxb.java.net/nonav/2.2.5-5/docs/ch03.html#compiling-xml-schema-mapping-of-xs-any 
and http://docstore.mik.ua/orelly/xml/schema/ch10_11.htm), if you have 
control over the schemas. If not, I'd be interested to hear if that is 
possible via a bindings file.

There seem to have been XJC plugins to customize wildcard binding modes 
(cf. 
http://stackoverflow.com/questions/9293634/jaxb-2-1-customize-xsany-binding 
and https://github.com/highsource/jaxb2-basics/), but that particular 
project seems to be dormant and the documentation for the WildcardPlugin 
gone.

Hope this helps at least a bit,
Sebastian

0
Sebastian
11/30/2016 6:13:47 PM
Am Mittwoch, 30. November 2016 19:13:56 UTC+1 schrieb Sebastian: 
> Have you tried googling this? Here's a post that might help:
> http://stackoverflow.com/questions/13610217/jaxb-compiling-issue-error-property-any-is-already-defined
> 
> I'm guessing the problem is caused by namespace="##other" occurring in 
> each sub-schema (although they do seem to share the same target 
> namespace, so it is a bit strange.) Have you made sure that the files 
> define mutually exclusive sets of types?

I have googled this many times, but the problem is, I cannot modify the XSD schema, because it is an external schema, which must be used exactly (strict) in this configuration.

In general I would modify the XSD, but here I need the schema in the posted case, without any changes


> Perhaps adding processContents="skip" in the schemas would help (see 
> https://jaxb.java.net/nonav/2.2.5-5/docs/ch03.html#compiling-xml-schema-mapping-of-xs-any 
> and http://docstore.mik.ua/orelly/xml/schema/ch10_11.htm), if you have 
> control over the schemas. If not, I'd be interested to hear if that is 
> possible via a bindings file.

Yes exactly, this is my question!
I cannot change the XSD, so I need to define the processContents with "skip" inside the bindings.xjb file, and I'm asking here for a solution of that.


> 
> There seem to have been XJC plugins to customize wildcard binding modes 
> (cf. 
> http://stackoverflow.com/questions/9293634/jaxb-2-1-customize-xsany-binding 
> and https://github.com/highsource/jaxb2-basics/), but that particular 
> project seems to be dormant and the documentation for the WildcardPlugin 
> gone.


Thanks I will take a look, but the question is still unanswerd :-)
How can I add the skip processingContents inside the binding file.

Thanks

Phil
0
Philipp
11/30/2016 9:04:53 PM
Am Mittwoch, 30. November 2016 22:05:02 UTC+1 schrieb Philipp Kraus:
> Thanks I will take a look, but the question is still unanswerd :-)

Some additional comments, the problems seems to be on the included schema, which is XSD 1.1 and Jaxb does not support the 1.1 definition, it supports XSD 1.0 only.

Therese seems to be a component https://xsom.java.net/ which should support 1.1, but not the xs:override, so the main question is how can I use the 1.1 schema without modifying the included schema.

Phil
0
Philipp
12/2/2016 12:30:02 PM
Am Freitag, 2. Dezember 2016 13:30:10 UTC+1 schrieb Philipp Kraus:
> Am Mittwoch, 30. November 2016 22:05:02 UTC+1 schrieb Philipp Kraus:
> > Thanks I will take a look, but the question is still unanswerd :-)
> 
> Some additional comments, the problems seems to be on the included schema, which is XSD 1.1 and Jaxb does not support the 1.1 definition, it supports XSD 1.0 only.
> 
> Therese seems to be a component https://xsom.java.net/ which should support 1.1, but not the xs:override, so the main question is how can I use the 1.1 schema without modifying the included schema.


We can solve the problem with the binding file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version = "2.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb = "http://java.sun.com/xml/ns/jaxb"
>
	<jaxb:bindings schemaLocation="network.xsd">
       		<jaxb:globalBindings generateIsSetMethod="false"/>
		<jaxb:schemaBindings>
         		<jaxb:package name="com.github.aptd.simulation.model.xml"/>
      		</jaxb:schemaBindings>
	</jaxb:bindings>
	<jaxb:bindings schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/infrastructure.xsd">
                <jaxb:bindings node="//xs:schema/xs:complexType[@name='eTrack']/xs:complexContent/xs:extension/xs:sequence/xs:any[@namespace='##other']">
                       	<jaxb:property name="any2"/>
                </jaxb:bindings>
	</jaxb:bindings>
	<jaxb:bindings schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/genericRailML.xsd">
               	<jaxb:bindings node="//xs:schema/xs:complexType[@name='tElementWithIDAndName']/xs:sequence/xs:any[@namespace='##other']">
                       	<jaxb:property name="any3"/>
               	</jaxb:bindings>
	</jaxb:bindings>
	<jaxb:bindings schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/timetable.xsd">
               	<jaxb:bindings node="//xs:schema/xs:complexType[@name='eTrainPart']/xs:complexContent/xs:extension/xs:sequence/xs:any[@namespace='##other']">
                       	<jaxb:property name="any4"/>
               	</jaxb:bindings>
	</jaxb:bindings>
</jaxb:bindings>
0
Philipp
12/7/2016 11:28:10 AM
Am 07.12.2016 um 12:28 schrieb Philipp Kraus:
> Am Freitag, 2. Dezember 2016 13:30:10 UTC+1 schrieb Philipp Kraus:
>> Am Mittwoch, 30. November 2016 22:05:02 UTC+1 schrieb Philipp Kraus:
>>> Thanks I will take a look, but the question is still unanswerd :-)
>>
>> Some additional comments, the problems seems to be on the included schema, which is XSD 1.1 and Jaxb does not support the 1.1 definition, it supports XSD 1.0 only.
>>
>> Therese seems to be a component https://xsom.java.net/ which should support 1.1, but not the xs:override, so the main question is how can I use the 1.1 schema without modifying the included schema.
>
>
> We can solve the problem with the binding file:
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <jaxb:bindings version = "2.1"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:jaxb = "http://java.sun.com/xml/ns/jaxb"
>>
> 	<jaxb:bindings schemaLocation="network.xsd">
>        		<jaxb:globalBindings generateIsSetMethod="false"/>
> 		<jaxb:schemaBindings>
>          		<jaxb:package name="com.github.aptd.simulation.model.xml"/>
>       		</jaxb:schemaBindings>
> 	</jaxb:bindings>
> 	<jaxb:bindings schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/infrastructure.xsd">
>                 <jaxb:bindings node="//xs:schema/xs:complexType[@name='eTrack']/xs:complexContent/xs:extension/xs:sequence/xs:any[@namespace='##other']">
>                        	<jaxb:property name="any2"/>
>                 </jaxb:bindings>
> 	</jaxb:bindings>
> 	<jaxb:bindings schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/genericRailML.xsd">
>                	<jaxb:bindings node="//xs:schema/xs:complexType[@name='tElementWithIDAndName']/xs:sequence/xs:any[@namespace='##other']">
>                        	<jaxb:property name="any3"/>
>                	</jaxb:bindings>
> 	</jaxb:bindings>
> 	<jaxb:bindings schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/timetable.xsd">
>                	<jaxb:bindings node="//xs:schema/xs:complexType[@name='eTrainPart']/xs:complexContent/xs:extension/xs:sequence/xs:any[@namespace='##other']">
>                        	<jaxb:property name="any4"/>
>                	</jaxb:bindings>
> 	</jaxb:bindings>
> </jaxb:bindings>
>

Thanks for sharing this. By renaming some of the any's you will indeed 
get rid of compiler complaints about multiple definitions. But does this 
also help with getting the desired wildcard binding mode 
(processContents="skip")? I suppose it will not, but I myself am unable 
to come up with anything better.

-- Sebastian
0
Sebastian
12/7/2016 10:48:46 PM
Am 07.12.2016 um 23:48 schrieb Sebastian:
> Am 07.12.2016 um 12:28 schrieb Philipp Kraus:
>> Am Freitag, 2. Dezember 2016 13:30:10 UTC+1 schrieb Philipp Kraus:
>>> Am Mittwoch, 30. November 2016 22:05:02 UTC+1 schrieb Philipp Kraus:
>>>> Thanks I will take a look, but the question is still unanswerd :-)
>>>
>>> Some additional comments, the problems seems to be on the included
>>> schema, which is XSD 1.1 and Jaxb does not support the 1.1
>>> definition, it supports XSD 1.0 only.
>>>
>>> Therese seems to be a component https://xsom.java.net/ which should
>>> support 1.1, but not the xs:override, so the main question is how can
>>> I use the 1.1 schema without modifying the included schema.
>>
>>
>> We can solve the problem with the binding file:
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>> <jaxb:bindings version = "2.1"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns:jaxb = "http://java.sun.com/xml/ns/jaxb"
>>>
>>     <jaxb:bindings schemaLocation="network.xsd">
>>                <jaxb:globalBindings generateIsSetMethod="false"/>
>>         <jaxb:schemaBindings>
>>                  <jaxb:package
>> name="com.github.aptd.simulation.model.xml"/>
>>               </jaxb:schemaBindings>
>>     </jaxb:bindings>
>>     <jaxb:bindings
>> schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/infrastructure.xsd">
>>
>>                 <jaxb:bindings
>> node="//xs:schema/xs:complexType[@name='eTrack']/xs:complexContent/xs:extension/xs:sequence/xs:any[@namespace='##other']">
>>
>>                            <jaxb:property name="any2"/>
>>                 </jaxb:bindings>
>>     </jaxb:bindings>
>>     <jaxb:bindings
>> schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/genericRailML.xsd">
>>
>>                    <jaxb:bindings
>> node="//xs:schema/xs:complexType[@name='tElementWithIDAndName']/xs:sequence/xs:any[@namespace='##other']">
>>
>>                            <jaxb:property name="any3"/>
>>                    </jaxb:bindings>
>>     </jaxb:bindings>
>>     <jaxb:bindings
>> schemaLocation="http://www.railml.org/files/download/schemas/2016/railML-2.3/schema/timetable.xsd">
>>
>>                    <jaxb:bindings
>> node="//xs:schema/xs:complexType[@name='eTrainPart']/xs:complexContent/xs:extension/xs:sequence/xs:any[@namespace='##other']">
>>
>>                            <jaxb:property name="any4"/>
>>                    </jaxb:bindings>
>>     </jaxb:bindings>
>> </jaxb:bindings>
>>
>
> Thanks for sharing this. By renaming some of the any's you will indeed
> get rid of compiler complaints about multiple definitions. But does this
> also help with getting the desired wildcard binding mode
> (processContents="skip")? I suppose it will not, but I myself am unable
> to come up with anything better.
>
> -- Sebastian

To pose the question another way: Is it still a wildcard after renaming? 
If not, won't you get validation problems with some XML files?

-- Sebastian
0
Sebastian
12/7/2016 10:54:42 PM
Reply: