JAXB绑定 - “无法兑现此转换自定义”

时间:2014-08-07 13:16:39

标签: xml data-binding jaxb xsd

我在架构中有自己的complexType,应该在 XML 中查找:

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

因此,包含一些文本的元素始终包含在CDATA中并具有属性。这是我迄今为止在 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>

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>

我无法摆脱的是compiler was unable to honor this conversion customization. It is attached to a wrong place, or its inconsistent with other bindings.

请问我该怎么办?我正在为这个问题奋斗几个小时,对我来说这是一个真正的阻碍。

1 个答案:

答案 0 :(得分:0)

作为部分答案,您需要按照以下方式修复cdata类型,以便获得文字内容:

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

副手我不确定您需要在绑定文件中定位哪个节点,但您可以尝试simpleContent