JAXB绑定 - “无法兑现此转换定制” [英] JAXB binding - "unable to honor this conversion customization"

查看:123
本文介绍了JAXB绑定 - “无法兑现此转换定制”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我自己的complexType在模式中应该看起来像这样的 XML



<动态-content language-id =en_US><! - [CDATA [256]] - >< / dynamic-content>



因此,包含一些文本的元素总是包含在CDATA中并具有属性。这是我迄今为止在 article-content.xsd 中所做的:

 <? xml version =1.0encoding =UTF-8?> 
< xs:schema xmlns:xs =http://www.w3.org/2001/XMLSchema
targetNamespace =http://www.ibacz.eu/veraext/xsd
xmlns:tns =http://www.ibacz.eu/veraext/xsdelementFormDefault =qualifiedattributeFormDefault =unqualified>

< xs:complexType name =cdata>
< xs:attribute name =language-idtype =xs:string/>
< / xs:complexType>

< xs:element name =root>
< xs:complexType>
< xs:sequence>
< xs:element name =dynamic-elementmaxOccurs =unbounded>
< xs:complexType>
< xs:sequence>
< xs:element name =dynamic-contenttype =tns:cdata/>
< / xs:sequence>
< xs:attribute name =nametype =xs:string/>
< xs:attribute name =indextype =xs:integer/>
< xs:attribute name =typetype =xs:string/>
< xs:attribute name =index-typetype =xs:string/>
< / xs:complexType>
< / xs:element>
< / xs:sequence>
< xs:attribute name =available-localestype =xs:string/>
< xs:attribute name =default-localetype =xs:string/>
< / xs:complexType>
< / xs:element>
< / xs:schema>

bindings.xsd

 < jaxb:bindingings xmlns:jaxb =http://java.sun.com/xml/ns/jaxbxmlns:xs =http:// www.w3.org/2001/XMLSchema
xmlns:xjc =http://java.sun.com/xml/ns/jaxb/xjcxmlns:xsi =http://www.w3。 org / 2001 / XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0。 xsd
version =2.1>

< jaxb:bindings schemaLocation =article-content.xsdnode =/ xs:schema>
< jaxb:bindings node =xs:complexType [@ name ='cdata']>
< xjc:javaType name =Stringadapter =eu.ibacz.veraext.backofficebridge.core.util.AdapterCDATA/>
< / jaxb:bindings>
< / jaxb:bindings>

< / jaxb:bindings>

我无法摆脱的是编译器无法兑现转换定制。它附加到错误的地方,或者与其他绑定不一致。



请问我该怎么办?我正在与这个问题打几个小时,这对我来说是一个真正的阻挡。

解决方案

作为部分答案,你需要修复您的 cdata 类型,以便您可以使用文本内容:

  < complexType name =cdata> 
< simpleContent>
< extension base =string>
< attribute name =languagetype =string/>
< / extension>
< / simpleContent>
< / complexType>

离开我不知道你需要在绑定文件中定位哪个节点,但是你可以尝试 simpleContent


I have my own complexType in schema that should look in XML something like this:

<dynamic-content language-id="en_US"><!--[CDATA[256]]--></dynamic-content>

Therefore element containing some text always wrapped in CDATA and having attribute. This is what I've done so far in article-content.xsd:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.ibacz.eu/veraext/xsd"
xmlns:tns="http://www.ibacz.eu/veraext/xsd" elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:complexType name="cdata">
        <xs:attribute name="language-id" type="xs:string" />
    </xs:complexType>

    <xs:element name="root"> 
        <xs:complexType>
            <xs:sequence>
                <xs:element name="dynamic-element" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:sequence>
                        <xs:element name="dynamic-content" type="tns:cdata" />
                    </xs:sequence>
                    <xs:attribute name="name" type="xs:string" />
                    <xs:attribute name="index" type="xs:integer" />
                    <xs:attribute name="type" type="xs:string" />
                    <xs:attribute name="index-type" type="xs:string" />
                  </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="available-locales" type="xs:string" />
            <xs:attribute name="default-locale" type="xs:string" />
        </xs:complexType>
    </xs:element>
</xs:schema>

and bindings.xsd:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
           version="2.1">

    <jaxb:bindings schemaLocation="article-content.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='cdata']">
            <xjc:javaType name="String" adapter="eu.ibacz.veraext.backofficebridge.core.util.AdapterCDATA"/>
        </jaxb:bindings>
    </jaxb:bindings> 

</jaxb:bindings>

What I can't get rid of is compiler was unable to honor this conversion customization. It is attached to a wrong place, or its inconsistent with other bindings.

Please what should I do? I'm fighting with this problem for hours and it is a real blocker for me.

解决方案

As a partial answer you need to fix your cdata type as follows so you can have text content:

    <complexType name="cdata">
        <simpleContent>
            <extension base="string">
                <attribute name="language" type="string"/>
            </extension>
        </simpleContent>
    </complexType>

Off hand I'm not sure which node you need to target in the binding file, but you could try simpleContent.

这篇关于JAXB绑定 - “无法兑现此转换定制”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆