Sunday, January 20, 2013

XML Schema

<xs:schema xmlns:xs="">
  <xs:element name="person">
        <xs:element name="fname" type="xs:string"/>
        <xs:element name="initial" type="xs:string"
        <xs:element name="lname" type="xs:string"/>
        <xs:element name="address" type="xs:string"
          <xs:element name="major" type="xs:string"/>
          <xs:element name="minor" type="xs:string"
              minOccurs="2" maxOccurs="2"/>

This question deals with the xs:element, xs:sequence, and xs:choice elements in XML Schema. In order for XML to be valid according to the specified schema:The elements contained in a sequence must appear in exactly the same order as specified in the xs:sequence.Exactly one of the elements contained in an xs:choice must appear.If an element specifies a minOccurs attribute, the XML must contain at least that many instances of the element.If an element specifies a maxOccurs attribute, the XML must not contain more than that many instances of the element.If minOccurs and maxOccurs are not specified, their default value is 1.Elements not defined as a part of a sequence or choice cannot occur inside the corresponding xs:sequence and xs:choice. The given schema specifies the following constraints: The "fname", "initial", "lname", and "address" elements must occur in that sequence. The "initial" element is optional due to its minOccurs value being 0.The "address" element can occur either 1 or 2 times due to its maxOccurs value being 2.After the "address" element, either exactly one "major" element or exactly 2 "minor" elements can occur, but not both. Elements not defined as a part of this schema specification are not allowed to occur as a part of the "person" element.

    <address>123 Public Avenue</address>
    <address>Seattle, WA 98001</address>
    <major>Computer Science</major>

Thanks for free knowledge