views:

18

answers:

1

I am newbie in xml schema. Is there any possiblility to define that element starts with some characater or symbol. I mean to say, <xs:element minOccurs="1" maxOccurs="1" name="Header"> <xs:complexType> <xs:sequence> <xs:sequence> <xs:element maxOccurs="1" minOccurs="1" name="NAME_STUDENTS"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="10"/> </xs:restriction> </xs:simpleType> </xs:element>

is there any possible way to define a pattern or tag in xml schema that name of student starts with 'P'??And schema should recognize the text as element NAME_STUDENTS only if the text starts with 'P'

A: 

I'm not sure if I fully understand your question but concerning the name element restriction you should look into Xml Schema Regular Expressions.

In your case this would look like this:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >

    <xs:element name="Header">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="NAME_STUDENTS" type="filtered-students" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:simpleType name="filtered-students">
        <xs:restriction base="xs:string">
            <xs:pattern value="^[P]?"/>
        </xs:restriction>
    </xs:simpleType>

</xs:schema>

... but I must confess I'm not really a regex hero so you may want to check the pattern with somebody more proficient.

Filburt