簡體   English   中英

JAXB綁定-“無法接受此轉換定制”

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

我在模式中有我自己的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. compiler was unable to honor this conversion customization. It is attached to a wrong place, or its inconsistent with other bindings.

請問我該怎么辦? 我為這個問題奮戰了好幾個小時,對我來說這是一個真正的阻礙。

作為部分回答,您需要按以下方式修復cdata類型,以便可以使用文本內容:

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

臨時而言,我不確定您需要在綁定文件中定位哪個節點,但是您可以嘗試simpleContent

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM