将 JAXB 和 JAXWS 组合起来以生成导入的 XML 模式

发布于 2024-10-27 09:19:15 字数 1404 浏览 4 评论 0原文

使用 wsimport 时,如何为 WSDL 中导入的 XSD 指定 JAXB 绑定?

我尝试了以下绑定,这会导致错误“ //xs:element[@name='isFoobar'] 的 XPath 计算导致空目标节点”。

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="example.wsdl"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:bindings node="wsdl:definitions">
        <jaxws:bindings node="wsdl:types" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
            <jaxws:bindings
                node="//xs:schema[@targetNamespace='http://www.example.org/']">
                <jaxb:globalBindings>
                    <xjc:serializable uid="10000001" />
                </jaxb:globalBindings>
                <jaxb:bindings
                    node="//xs:element[@name='isFoobar']">
                    <jaxb:typesafeEnumClass name="IsFoobar">
                        <jaxb:typesafeEnumMember value="01" name="TRUE" />
                        <jaxb:typesafeEnumMember value="02" name="FALSE" />
                    </jaxb:typesafeEnumClass>
                </jaxb:bindings>
            </jaxws:bindings>
        </jaxws:bindings>
    </jaxws:bindings>
</jaxws:bindings>

有什么想法吗?

How can I specify a JAXB Binding for an imported XSD within a WSDL when using wsimport?

I tried following binding, which causes the error "XPath evaluation of //xs:element[@name='isFoobar'] results in an empty target node".

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="example.wsdl"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:bindings node="wsdl:definitions">
        <jaxws:bindings node="wsdl:types" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
            <jaxws:bindings
                node="//xs:schema[@targetNamespace='http://www.example.org/']">
                <jaxb:globalBindings>
                    <xjc:serializable uid="10000001" />
                </jaxb:globalBindings>
                <jaxb:bindings
                    node="//xs:element[@name='isFoobar']">
                    <jaxb:typesafeEnumClass name="IsFoobar">
                        <jaxb:typesafeEnumMember value="01" name="TRUE" />
                        <jaxb:typesafeEnumMember value="02" name="FALSE" />
                    </jaxb:typesafeEnumClass>
                </jaxb:bindings>
            </jaxws:bindings>
        </jaxws:bindings>
    </jaxws:bindings>
</jaxws:bindings>

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱格式化 2024-11-03 09:19:15

抱歉,死线程,我遇到了这个问题,虽然这是谷歌上出现的带有各种关键字组合的第一个答案之一,但它没有包含我最终使用的答案。


对于导入的模式,在 WSDL 内的导入的 XSD 上指定 JAXB 绑定的最简单方法是...将其视为完全不同的模式!

简短示例:

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>

无论此 xsd 导入何处(无论是在 wsdl 的根目录还是在嵌套导入中),我都需要编写来绑定我的“ThingThatNeedsToBeBound”我的自定义绑定是:

customBindings.xml

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

因此,它就像常规情况一样,只是您指定了 schemaLocation,但是您可以将导入的架构视为一个整体,而不是某些内容的一部分。

我希望这能帮助其他人解决这个问题。


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

(注意:在源代码中,解决方案似乎更复杂,所以我的情况可能比他们描述的更简单,我尽管如此,我还是找到了我的解决方案!)

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 !)

痴者 2024-11-03 09:19:15

我很久以前做过类似的事情,我认为您需要指定要使用 XPath 选择的节点,如下所示:

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

或者将 xs:complexType 替换为您在此处使用的任何类型。希望它能解决您的问题。

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.

装迷糊 2024-11-03 09:19:15

我第一次尝试解决这个问题是尝试以某种方式使用 XPath 或多个 jxb:binding 元素,但这不起作用。据我所知,XPath 没有针对导入的模式进行正确的验证,除非它全部被重写并与 DOM 混合在一起。

所以我解决这个问题的方法是使用 内联自定义 在导入的 XSD 中。我没有使用多个嵌套导入来测试这种方法,但如果您有访问权限和时间来修改所有导入的 XSD,这应该可以解决。在我看来,只有当您需要生成映射并且映射完成后可以从 XSD 中擦除/删除时,这才是必要的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文