XML Tutorial/XML Schema/group

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

Defining Named Groups and Referencing a Named Group

   <source lang="xml">

A group defines a list of related elements that will all be used together in one or more other elements. You can reference a group in a complex type definition, a sequence, a set of choices, an unordered group, or in other named groups.

<?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:group name="physical_traits">
   <xsd:sequence>
     <xsd:element name="weight" type="xsd:string" />
     <xsd:element name="length" type="xsd:string" />
     <xsd:element name="distinguishing" type="xsd:string" />
   </xsd:sequence>
 </xsd:group>
 <xsd:element name="individual">
   <xsd:complexType>
     <xsd:group ref="physical_traits" />
   </xsd:complexType>
 </xsd:element>
 

</xsd:schema></source>


<group> Declarations

   <source lang="xml">

<group name="name of global group"> All global <group> declarations must be named. The basic structure of a global <group> declaration follows: <group name="NCName"

   ref="NCName"
   maxOccurs="nonNegativeInteger | unbounded"
   minOccurs="nonNegativeInteger"
   id="ID">
 Content: (annotation?, (all | choice | sequence))

</group></source>


<group> References

   <source lang="xml">

The <group> reference declaration allows you to refer to global element groups within your content model. <group ref="global group definition"

      minOccurs="non negative number" 
      maxOccurs="non negative number or unbounded"> 

This can be done by including a ref attribute and specifying the name of the global <group> declaration: <group name="NameGroup">

   <sequence> 
       <element name="first" type="string" minOccurs="1" maxOccurs="unbounded"/> 
       <element name="middle" type="string" minOccurs="0" maxOccurs="1"/> 
       <element name="last" type="string"/> 
   </sequence> 

</group> <element name="name">

   <complexType> 
       <group ref="target:NameGroup"/> 
       <attribute name="title" type="string"/> 
   </complexType> 

</element></source>