开发者

JAXB annotations to deal with same element name in different namespaces

The problem that I am trying to solve is that JAXB cannot handle the parent and inherited objects of the same name in different namespaces.

I have two schemas:

schemaA.xsd

<xs:schema xmlns:A=开发者_运维问答"...">
<xs:complexType name="mytype">
...

schemaB.xsd

<xs:schema xmlns:B="..." xmlns:A="...">
<xs:import namespace="..." schemaLocation="schemaA.xsd"/>
<xs:complexType name="mytype">
...

Here the mytype definition is different in schemaB. And no, I have no control over the schemas, they are large commercial thirdparty supplied. How do people deal with this situation? The point is that schemaB references schemaA and indeed uses many elements from schemaA. JAXB cannot run on B alone, but it can and does on A alone.

One last point, there are many many elements involved, cannot add JAXB customization to all of them. Well it would be a lot of work.


Funny how the JAXB questions get hardly any response.

@jamh

I assume you're trying to run xjc to generate Java stubs for the third party schema(s). Have you tried specifying a different package name for each namespace? This can be done in a custom binding file or on the command line with the -p argument...

xjc -p com.your.package.name /path/to/xsd


In element declaration you need to provide different propertyName:

<xs:element ref="namespace1:foo">
    <xs:annotation>
        <xs:appinfo>
            <jaxb:property name="fooElement"/> // here you see changing the name
        </xs:appinfo>
    </xs:annotation>
</xs:element>

Doing so when you have two elements with name "foo" and one of them has a declaration, when one of them does not.

You will have generated (by xjc) an object with properties:

Foo foo;
Foo fooElement;

So there will no conflict.

You can read more about bindings on: http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜