Combine JAXB and JAXWS for an imported XML Schema

非 Y 不嫁゛ 提交于 2019-12-01 00:54:59

I did something similar ages ago, I think you need to specify the node to select with XPath as follows:

//xs:element[@name='isFoobar']/xs:complexType

Or replace xs:complexType with whatever kind of type you are using here. Hopefully it will fix your probelm.

My first try at resolving this was trying to somehow use XPath or multiple jxb:binding elements, but that didn't work. As far as I know the XPath just isn't validated properly against imported schemas unless it would all be rewritten and mashed together with DOM.

So the way I resolved this problem was by using inline customizations in the imported XSD. I didn't test this approach with multiple nested imports, but if you got access and time to modify all the imported XSDs this should work out ok. In my opinion this is only necessary if you need to generate the mapping and can be scrubbed/removed from the XSD once the mapping is done.

Sorry for the necro-threading, I encountered this problem and although this is one of the first answer that showed up on google with various key word combination it didn't hold the answer I ended up using.


For imported schemas, the easiest way to specify a JAXB binding on an imported XSD within a WSDL is... to treat it as a completely different schema !

Short example :

MyXSD.xsd

<xsd:schema targetNamespace="whatever"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="ThingThatNeedsToBeBound">
        <!-- Whatever this is made of -->
    </xs:complexType>
</xsd:schema>

No matter where this xsd is imported (wether it's at the root of the of my wsdl or within a nested import), all I need to write to bind my "ThingThatNeedsToBeBound" in my custom binding is :

customBindings.xml

<jaxb:bindings schemaLocation="Path/To/MyXSD.xsd" node="/xs:schema/xs:complexType[@name='ThingThatNeedsToBeBound']">
    <!-- your custom binding -->
</jaxb:bindings>

So, it's just like a regular case, except that you specify the schemaLocation, but then you can consider the imported schema as a whole itself instead of a part of something.

I hope this will help others stumbling upon this problem.


Source : http://www.oracle.com/technetwork/articles/grid/jax-ws-jaxb-customization-082750.html

(Note : in the source, the solution seems way more complicated, so my case might have been simpler than what they described, I found my solution using that none the less !)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!