tags:

views:

14

answers:

1

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"&gt;
    <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>
A: 

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

John Saunders
I just added the schema in my initial question. Please review that. I am checking the length of both article_artextref and Provider ID.
Ashique Anwar
All that your XSD does is validate the values of the "name" property. You don't validate the contents of the "attribute" elements, and you certainly don't validate that the contents have different types based on the "name" attribute. XML Schema can't do those things.
John Saunders