使用 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>
..以及以下绑定定义
<?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>
complextType MetaTypeSimpleContent与simpleContent的绑定工作正常。但是 complexType MetaTypeComplexContent与complexContent的绑定没有。为什么?我收到以下错误:
[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.