XML Tutorial/XML Schema/Venetian Blind

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

Venetian Blind Model

The Venetian Blind Model encourages the use of complexTypes rather than just the declaration of elements. 
The idea behind types and the Venetian Blind Model is analogous to the notion of defining a class and using the class to create an object.
<?xml version = "1.0" ?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
           targetNamespace = "http://www.wbex.ru/Customers"
           xmlns = "http://www.wbex.ru/Customers"
           elementFormDefault = "qualified"
           attributeFormDefault = "unqualified">
   
   <xs:element name = "Customer" type = "NameType" />
   
   <xs:complexType name = "NameType">
      <xs:sequence>
         <xs:element name = "FirstName" type = "xs:string" />
         <xs:element name = "MiddleName" type = "xs:string" 
                     minOccurs = "0" maxOccurs = "1" />
         <xs:element name = "LastName" type = "xs:string" />
      </xs:sequence>
      <xs:attribute name = "customerID" type = " xs:integer" 
                    use = "required" />
      <xs:attribute name = "clubCardMember" type = "xs:boolean" />
   </xs:complexType>
   
</xs:schema>

File: Data.xml
<?xml version = "1.0" ?>
<Customer xmlns = "http://www.wbex.ru/Customers"
          xmlns:cust = "http://www.wbex.ru/Customers"
          customerID = "2442"
          clubCardMember = "true" >
   <FirstName>first</FirstName>
   <MiddleName>middle</MiddleName>
   <LastName>last</LastName>
</Customer>