开发者

XSD with for elements with same name

I am trying to create a Xml schema for a xml file that looks like following

<attributes>
 <attribute name="article_artextref">123213213</attribute>
 <attribute name="ProviderID">ABC</attribute>
</attributes>

What I am trying to accomplish is check if an attribute named "article_artextref" exist and make sure the lenght of its value is larger than 1. I dont want to validate the lenght of attribute name "ProviderID" and the length for provider ID can be 0.

Please help.

I am adding the xml schema I have which so far checks the length for both of the elements.

<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:elemen开发者_StackOverflowt>
    <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>


Sorry, but XML Schema can't handle anything like that. You need different element names if you want different element content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜