XML Tutorial/XML Schema/all

Материал из Web эксперт
Перейти к: навигация, поиск

<all> Declarations

<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"
            <element name="first" type="string"/
            <element name="middle" type="string"/
            <element name="last" type="string"/
        <attribute name="title" type="string"/

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

Allowing Elements to Appear in Any Order

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"
    <xsd:element name="subspecies" type="subspeciesType"/>
  <xsd:complexType name="subspeciesType">
      <xsd:element name="region" type="xsd:string" minOccurs="0" />
      <xsd:element name="population" type="xsd:string" />

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