XSD用于具有相同名称的元素

时间:2010-06-18 22:21:32

标签: xml xsd

我正在尝试为xml文件创建一个类似于

的Xml架构
<attributes>
 <attribute name="article_artextref">123213213</attribute>
 <attribute name="ProviderID">ABC</attribute>
</attributes>

我想要完成的是检查名为“article_artextref”的属性是否存在,并确保其值的长度大于1.我不想验证属性名称“ProviderID”的长度和提供者​​的长度ID可以是0.

请帮忙。

我正在添加我到目前为止检查两个元素的长度的xml架构。

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="ST_attribute">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="attributes">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="attribute" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="attribute">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="ST_attribute">
                    <xs:attribute name="name" use="required">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="ProviderID"/>
                                <xs:enumeration value="article_artextref"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
</xs:schema>

1 个答案:

答案 0 :(得分:0)

很抱歉,但XML Schema无法处理这样的事情。如果您需要不同的元素内容,则需要不同的元素名称。