0
我试图创建一个XML文件,它看起来像下面的XML模式元素XSD与具有相同名称的
<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>
我刚刚在我最初的问题中添加了架构。请检查一下。我正在检查article_artextref和Provider ID的长度。 – 2010-06-18 22:30:19
您的XSD所做的只是验证“name”属性的值。您不验证“属性”元素的内容,并且您当然不会根据“name”属性验证内容是否具有不同的类型。 XML Schema不能做这些事情。 – 2010-06-18 22:47:31