Xml 声明具有属性和文本的类型,受模式限制

Xml 声明具有属性和文本的类型,受模式限制,xml,xsd,Xml,Xsd,我想声明下一种类型: <partCode negation="true|false">\*|[0-9]{1,9}</name> 但它包含一个错误: 内容模型中已存在“extension”元素 我如何才能做到这一点?您不能在同一步骤中限制和扩展。首先定义满足模式的xs:string限制;然后定义此属性的扩展,添加属性。 <xs:complexType name="PartCodeValue"> <xs:simpleContent>

我想声明下一种类型:

<partCode negation="true|false">\*|[0-9]{1,9}</name>
但它包含一个错误:

内容模型中已存在“extension”元素


我如何才能做到这一点?

您不能在同一步骤中限制和扩展。首先定义满足模式的
xs:string
限制;然后定义此属性的扩展,添加属性。


<xs:complexType name="PartCodeValue">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute name="negation" type="xs:boolean" use="optional" default="false" />
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>
<xs:complexType name="PartCode">
    <xs:simpleContent>
        <xs:restriction base="PartCodeValue">
            <xs:pattern value="\*|[0-9]{1,9}" />
        </xs:restriction>
    </xs:simpleContent>
</xs:complexType>

请您举个例子,我很乐意接受。
<xs:complexType name="PartCodeValue">
    <xs:simpleContent>
        <xs:extension base="xs:string">
            <xs:attribute name="negation" type="xs:boolean" use="optional" default="false" />
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>
<xs:complexType name="PartCode">
    <xs:simpleContent>
        <xs:restriction base="PartCodeValue">
            <xs:pattern value="\*|[0-9]{1,9}" />
        </xs:restriction>
    </xs:simpleContent>
</xs:complexType>