XML Tutorial/XML Schema/group

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

Defining Named Groups and Referencing a Named Group

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

<group> Declarations

<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"
    maxOccurs="nonNegativeInteger | unbounded"
  Content: (annotation?, (all | choice | sequence))

<group> References

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"> 
        <element name="first" type="string" minOccurs="1" maxOccurs="unbounded"/> 
        <element name="middle" type="string" minOccurs="0" maxOccurs="1"/> 
        <element name="last" type="string"/> 
<element name="name"> 
        <group ref="target:NameGroup"/> 
        <attribute name="title" type="string"/>