Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xjb binding with xs:any

886 views
Skip to first unread message

Philipp Kraus

unread,
Nov 29, 2016, 2:07:17 PM11/29/16
to
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

Sebastian

unread,
Nov 30, 2016, 1:13:56 PM11/30/16
to
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

Philipp Kraus

unread,
Nov 30, 2016, 4:05:02 PM11/30/16
to
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

Philipp Kraus

unread,
Dec 2, 2016, 7:30:10 AM12/2/16
to
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

Philipp Kraus

unread,
Dec 7, 2016, 6:28:32 AM12/7/16
to
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>

Sebastian

unread,
Dec 7, 2016, 5:48:53 PM12/7/16
to
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

Sebastian

unread,
Dec 7, 2016, 5:54:49 PM12/7/16
to
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 new messages