Xml XJC-[ERROR]编译器无法执行此属性自定义

Xml XJC-[ERROR]编译器无法执行此属性自定义,xml,xsd,jaxb,xjc,Xml,Xsd,Jaxb,Xjc,我在xjc中遇到了一个奇怪的问题,试图在java属性中映射元素。我希望有关于Test2的测试3的getter和setter 我将绑定设置为: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" v

我在
xjc
中遇到了一个奇怪的问题,试图在java属性中映射元素。我希望有关于Test2的测试3的getter和setter

我将绑定设置为:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">
    <jaxb:globalBindings localScoping="toplevel" underscoreBinding="asCharInWord">
    </jaxb:globalBindings>
    <jaxb:bindings schemaLocation="test.xsd">
        <jaxb:schemaBindings>
            <jaxb:package name="test.detail" />
        </jaxb:schemaBindings>
        <jaxb:bindings node="//xsd:element[@name='TEST']">
            <jaxb:class name="Test"></jaxb:class>
        </jaxb:bindings>
        <jaxb:bindings node="//xsd:element[@name='TEST1']">
            <jaxb:class name="Test1" />
        </jaxb:bindings>
        <jaxb:bindings node="//xsd:element[@name='TEST2']">
            <jaxb:class name="Test2Impl" />
        </jaxb:bindings>
        <jaxb:bindings node="//xsd:element[@name='TEST3']">
            <jaxb:property name="test3" />
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

我创建了一个可以测试的元素。

首先,您需要修复XSD,以便定义与targetNamespace关联,并且元素ref是正确的

尝试:


但是,您仍然有一个更难的问题,即如何使用“TEST3”getter从其余的混合内容中选择TEST3子元素。JAXB将把它们全部映射到一个列表中

通过查看其他帖子,您可能会发现它可能有助于处理您的用例


(也许有人会写一个更好的答案,更详细地说明如何解决问题,但这可能很有帮助,我将按原样发布)。

谢谢@scott kurz,你的建议解决了我的问题,我承诺了一切
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="" elementFormDefault="qualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
    <xsd:element name="TEST1">
        <xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:element name="TEST2" maxOccurs="unbounded">
                    <xsd:complexType mixed="true">
                        <xsd:sequence>
                            <xsd:element name="TEST3" minOccurs="0" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="TEST">
        <xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:element ref="TEST1" minOccurs="0" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>
parsing a schema...
[WARNING] EmptyTargetNamespace: In schema document 'jaxb-generate-test/test.xsd',
the value of the 'targetNamespace' attribute cannot be an empty string.
  line 3 of jaxb-generate-test/test.xsd

[ERROR] compiler was unable to honor this property customization. 
It is attached to a wrong place, or its inconsistent with other bindings.
  line 20 of jaxb-generate-test/binding.xjb

[ERROR] (the above customization is attached to the following location in the schema)
  line 10 of jaxb-generate-test/test.xsd

Failed to parse a schema.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://myns" elementFormDefault="qualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:tns="http://myns">
    <xsd:element name="TEST1">
        <xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:element name="TEST2" maxOccurs="unbounded">
                    <xsd:complexType mixed="true">
                        <xsd:sequence>
                            <xsd:element name="TEST3" minOccurs="0" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="TEST">
        <xsd:complexType mixed="true">
            <xsd:sequence>
                <xsd:element ref="tns:TEST1" minOccurs="0" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>