XML Tutorial/XML Schema/all

Материал из Web эксперт
Версия от 11:26, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

<all> Declarations

   <source lang="xml">

<all> says that the elements within your content model may appear in any order. <all> must be the only content model declaration that appears as a child of a <complexType> definition. <all> cannot contain <sequence>, <choice>, or <group> declarations. <all> declaration"s children may appear once each in the instance document. Within the <all>, the values for minOccurs/maxOccurs are limited to 0 or 1. <all> is used when the expected content is known, but not the order. Suppose you declared the <name> content model using the <all>: <element name="name"

   <complexType>
       <all>
           <element name="first" type="string"/
           <element name="middle" type="string"/
           <element name="last" type="string"/
       </all>
       <attribute name="title" type="string"/
   </complexType>

</element>

The allowable content for a <name> element declared using an <all> declaration might include <name>

   <first>first</first> 
   <middle>middle</middle> 
   <last>last</last> 

</name> or <name>

   <first>first</first> 
   <last>last</last> 
   <middle>middle</middle> 

</name></source>


Allowing Elements to Appear in Any Order

   <source lang="xml">

The members of an "all" group may appear once or not at all, in any order. The minOccurs and maxOccurs attributes may only be set to 0 or 1. An all group can only contain individual element declarations or references, not other groups. An all group can only be contained either a complex type definition or a named group definition. File: Schema.xsd <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

 targetNamespace="http://www.wbex.ru" 
 xmlns="http://www.wbex.ru"
 elementFormDefault="qualified">
   <xsd:element name="subspecies" type="subspeciesType"/>
 <xsd:complexType name="subspeciesType">
   <xsd:all>
     <xsd:element name="region" type="xsd:string" minOccurs="0" />
     <xsd:element name="population" type="xsd:string" />
   </xsd:all>
 </xsd:complexType>

</xsd:schema>

File: Data.xml <?xml version="1.0"?> <subspecies xmlns="http://www.wbex.ru">

 <population>3159</population>
 <region>India</region>

</subspecies></source>