XML/XML Schema/string — различия между версиями

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

Текущая версия на 11:26, 26 мая 2010

element with type xsd:string

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <fullName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:noNamespaceSchemaLocation="Schema.xsd">
  James Bond

</fullName>

File: Schema.xsd <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="fullName" type="xsd:string"/>

</xsd:schema>

</source>
   
  


Enumeration of string value

   <source lang="xml">

File: Data.xml <?xml version="1.0"?>

   <aircraft>F-16</aircraft>

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="aircraft">
       <xsd:simpleType>
           <xsd:restriction base="xsd:string">
               <xsd:enumeration value="Boeing 747"/>
               <xsd:enumeration value="F-16"/>
               <xsd:enumeration value="A-10"/>
           </xsd:restriction>
       </xsd:simpleType>
   </xsd:element>
   <xsd:element name="data">
       <xsd:complexType>
           <xsd:sequence>
               <xsd:element ref="aircraft" maxOccurs="2"/>
           </xsd:sequence>
       </xsd:complexType>
   </xsd:element>

</xsd:schema>

</source>
   
  


restruction based on string type

   <source lang="xml">

File: Data.xml <?xml version="1.0"?>

   <aircraft>F-16</aircraft>

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="data">
       <xsd:complexType>
           <xsd:sequence>
               <xsd:element name="aircraft" maxOccurs="2">
                   <xsd:simpleType>
                       <xsd:restriction base="xsd:string">
                           <xsd:enumeration value="Boeing 747"/>
                           <xsd:enumeration value="F-16"/>
                           <xsd:enumeration value="A-10"/>
                       </xsd:restriction>
                   </xsd:simpleType>
               </xsd:element>
           </xsd:sequence>
       </xsd:complexType>
   </xsd:element>

</xsd:schema>

</source>
   
  


String value based on pattern

   <source lang="xml">

File: Data.xml <?xml version="1.0"?> <target id="uuid:093a2da1-q345-739r"

       xmlns="http://www.wbex.ru"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=
                         "http://www.wbex.ru
                          Schema.xsd">
        <location>
               <latitude>32.904237</latitude>
               <longitude>73.620290</longitude>
               <uncertainty units="meters">2</uncertainty>
       </location>

</target> File: Schema.xsd <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema"

           targetNamespace="http://www.wbex.ru"
           xmlns:mti="http://www.wbex.ru"
           elementFormDefault="qualified">
   <element name="target">
       <complexType>
           <sequence>
               <element name="location" maxOccurs="unbounded">
                   <complexType>
                       <sequence>
                           <element name="latitude" type="mti:latType"/>
                           <element name="longitude" type="mti:lonType"/>
                           <element name="uncertainty" type="mti:uncertaintyType"/>
                       </sequence>
                   </complexType>
               </element>
           </sequence>
           <attribute name="id" type="string" use="required"/>
       </complexType>
   </element>
   <simpleType name="latType">
       <restriction base="string">
           <pattern value="[0-9]\.[0-9]{6}|[1-8][0-9]\.[0-9]{6}|90\.[0-9]{6}|-[0-9]\.[0-9]{6}|-[1-8][0-9]\.[0-9]{6}|-90\.[0-9]{6}"/>
       </restriction>
   </simpleType>
   <simpleType name="lonType">
       <restriction base="string">
           <pattern value="[0-9]\.[0-9]{6}|[1-9][0-9]\.[0-9]{6}|1[0-7][0-9]\.[0-9]{6}|180\.[0-9]{6}|-[0-9]\.[0-9]{6}|-[1-9][0-9]\.[0-9]{6}|-1[0-7][0-9]\.[0-9]{6}|-180\.[0-9]{6}"/>
       </restriction>
   </simpleType>
   <complexType name="uncertaintyType">
       <simpleContent>
           <extension base="nonNegativeInteger">
               <attribute name="units" use="required">
                   <simpleType>
                       <restriction base="string">
                           <enumeration value="meters"/>
                           <enumeration value="feet"/>
                       </restriction>
                   </simpleType>
               </attribute>
           </extension>
       </simpleContent>
   </complexType>

</schema>

</source>