XML/XML Schema/string

Материал из Web эксперт
Версия от 08:26, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

element with type xsd:string

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>



Enumeration of string value

File: Data.xml
<?xml version="1.0"?>
<data xmlns="http://www.wbex.ru"
                   xmlns:ex="http://www.wbex.ru"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation=
                              "http://www.wbex.ru
                               Schema.xsd">
    <aircraft>F-16</aircraft>
</data>
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>



restruction based on string type

File: Data.xml
<?xml version="1.0"?>
<data xmlns="http://www.wbex.ru"
                   xmlns:ex="http://www.wbex.ru"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation=
                              "http://www.wbex.ru
                               Schema.xsd">
    <aircraft>F-16</aircraft>
</data>
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>



String value based on pattern

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>