Java JAXB—当属性已经定义并使用绑定时,它';它不使用*complexContent*

Java JAXB—当属性已经定义并使用绑定时,它';它不使用*complexContent*,java,xml,xsd,jaxb,xjb,Java,Xml,Xsd,Jaxb,Xjb,使用JAXB生成Java类。 我使用下面的XSD方案 <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msb=

使用JAXB生成Java类。 我使用下面的XSD方案

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msb="http://schemas.microsoft.com/developer/msbuild/2003" elementFormDefault="qualified">

    <!-- Working -->
    <xs:complexType name="MetaTypeSimpleContent">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="Name" />
                <xs:attribute type="xs:string" name="Scheme" />
                <xs:attribute type="xs:string" name="Value" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <!-- Not Working -->
    <xs:complexType name="MetaTypeComplexContent">
        <xs:complexContent>
            <xs:extension base="msb:BaseType">
                <xs:attribute name="MyName" type="xs:string" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="BaseType">      
        <xs:attribute name="MyName" type="xs:string" />                
    </xs:complexType>

</xs:schema>

错误消息似乎非常清楚地指出了问题:

[错误]ct道具正确。4:类型为“MetaTypeComplexContent”的错误。使用相同的名称和目标命名空间指定了重复的属性用法。重复属性的名称为“MyName”

扩展复杂类型时,不应重新声明继承的内容。也许您打算在扩展复杂类型中添加一个新属性,但忘记更改名称了

要修复错误,请执行以下操作之一:

  • 删除复杂类型扩展
  • 更改复杂类型扩展中属性的名称或命名空间
<?xml version="1.0" encoding="UTF-8"?>
<bindings   xmlns="http://java.sun.com/xml/ns/jaxb" 
            xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            version="2.1">

    <bindings schemaLocation="Test.xsd" version="1.0">
        <!-- Customise the package name -->
        <schemaBindings>
            <package name="com.example.schema" />
        </schemaBindings>

        <!-- Working -->
        <bindings node="//xs:complexType[@name='MetaTypeSimpleContent']">
            <bindings node=".//xs:attribute[@name='Value']">
                <property name="ValueAttribute" />
            </bindings>
        </bindings>

        <!-- Not Working -->
        <bindings node="//xs:complexType[@name='MetaTypeComplexContent']/xs:complexContent/xs:extension/xs:attribute[@name='MyName']">            
            <property name="MyName3" />
        </bindings>

    </bindings>

</bindings>
[ERROR] ct-props-correct.4: Error with type 'MetaTypeComplexContent'. Duplicate attribute usages were specified with the same name and target namespace. The name of the duplicate attribute is 'MyName'.
   Line 19 of file: / D: /temp/Stackoverflow/Test.xsd

A schema could not be parsed.