#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    40
    Rep Power
    7

    How to validate this xml input?


    I'm new to XML and I need help. I have thos XML code on which I have to make a scheme validator:

    Code:
     
    <?xml version="1.0" encoding="UTF-8"?>
    <users>
    <user>
        <family pol="m">Peter</family>
        <age>40</age>
        <email>ppenzov@ii.com</email>
    </user>
    <user>
        <family pol="w">Penz</family>
        <age>65</age>
    </user>
    <user>
        <family pol="w">Penzov</family>
        <age>19</age>
        <email>pppenzov@ii.com</email>
    </user>
    </users>


    The xml scheme must follow these rules:

    family, age and email must be strictly in order

    family - must be repeated once and maximum 20 symbols

    age - must be repeated once, number between 1 and 100

    email - must be repeated once, 0 or 1, String between 5 and 10 symbols

    Would you help me please to create a very basic example?

    So far I have done this:

    Code:
    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.w3schools.com"
    xmlns="http://www.w3schools.com"
    elementFormDefault="qualified">
     
    <xs:element name="user">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="family" type="xs:string">
         <xs:restriction base="xs:string">
                <xs<img src="http://images.devshed.com/fds/smilies/tongue.gif" border="0" alt="" title="Stick Out Tongue" class="inlineimg" />attern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
            <xs:enumeration value="family" maxOccurs="1"/>
                <xs:length value="20"/>
             </xs:restriction>
          </xs:element name="family" type="xs:string">
          <xs:element name="age" type="xs:intreger">
        <xs:restriction base="xs:integer">
                <xs:minInclusive value="1"/>
                <xs:maxInclusive value="100"/>
            <xs:enumeration value="age" maxOccurs="1"/>
             </xs:restriction>
          </xs:element name="age" type="xs:intreger">
          <xs:element name="email" type="xs:string">
         <xs:restriction base="xs:string">
                 <xs:minLength value="5"/>
                 <xs:maxLength value="10"/>
             <xs:enumeration value="email" maxOccurs="1"/>
             </xs:restriction>
          </xs:element name="email" type="xs:string">
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    Last edited by rcbandit; June 22nd, 2013 at 02:12 AM.

IMN logo majestic logo threadwatch logo seochat tools logo