XML Tutorial/XML Schema/schemaLocation

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

One xml document with two xml schemas

File: Data.xml
<?xml version="1.0"?>
<data xmlns="http://www.demo2s.ru"
      xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
      xsi:schemaLocation=
                "http://www.wbex.ru sensor.xsd
                 http://www.demo2s.ru data.xsd">
    <sensor>gamma</sensor>
</data>

File: data.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
            targetNamespace="http://www.demo2s.ru"
            xmlns="http://www.demo2s.ru"
            xmlns:t="http://www.wbex.ru"
            elementFormDefault="qualified">
    <xsd:element name="data">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="sensor" type="t:sensor_type"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

File: sensor.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
            targetNamespace="http://www.wbex.ru"
            xmlns="http://www.wbex.ru"
            elementFormDefault="qualified">
    <xsd:simpleType name="sensor_type">
       <xsd:restriction base="xsd:string">
           <xsd:enumeration value="alpha"/>
           <xsd:enumeration value="beta"/>
       </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>