简体   繁体   English

JAXB绑定-“无法接受此转换定制”

[英]JAXB binding - “unable to honor this conversion customization”

I have my own complexType in schema that should look in XML something like this: 我在模式中有我自己的complexType,应该在XML中看起来像这样:

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

Therefore element containing some text always wrapped in CDATA and having attribute. 因此,包含某些文本的元素始终包裹在CDATA中并具有属性。 This is what I've done so far in article-content.xsd : 到目前为止,这是我在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 : 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. 我不能摆脱的是compiler was unable to honor this conversion customization. It is attached to a wrong place, or its inconsistent with other bindings. 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: 作为部分回答,您需要按以下方式修复cdata类型,以便可以使用文本内容:

    <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 . 临时而言,我不确定您需要在绑定文件中定位哪个节点,但是您可以尝试simpleContent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM