XML/XML Schema/anyURI

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

anyURI as attribute type

File: Data.xml
<?xml version="1.0"?>
<AttributeExamples 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">
    <image/>                                               
    <image src="http://www.wbex.ru/style/LOGO.PNG"/>  
</AttributeExamples>
File: Schema.xml
<?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="image">
        <xsd:complexType>
            <xsd:attribute name="src" type="xsd:anyURI"/>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="AttributeExamples">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="image" maxOccurs="2"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>



Element with only attribute

File: Data.xml
<?xml version="1.0"?>
<AttributeExamples xmlns="http://www.wbex.ru"
                   xmlns:i="http://www.wbex.ru"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation=
                              "http://www.wbex.ru
                               Schema.xsd">
    <image/>
    <image i:src="http://www.wbex.ru/style/logo.png"/>
</AttributeExamples>

File: Schema.xml
<?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="image">
        <xsd:complexType>
            <xsd:attribute ref="src"/>
        </xsd:complexType>
    </xsd:element>
    <xsd:attribute name="src" type="xsd:anyURI"/>
    <xsd:element name="AttributeExamples">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="image" maxOccurs="2"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>



xs:enumeration and xs:anyURI

File: Data.xml
<?xml version="1.0"?>
<Book xmlns="http://www.wbex.ru"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.wbex.ru Schema.xsd">
   http://www.w3.org/TR/xmlschema-0/
</Book>
File: Schema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.wbex.ru" 
  xmlns="http://www.wbex.ru"
  elementFormDefault="qualified">

    <xs:element name="Book" type="schemaRecommendations"/>
  <xs:simpleType name="schemaRecommendations">
    <xs:restriction base="xs:anyURI">
      <xs:enumeration value="http://www.w3.org/TR/xmlschema-0/" />
      <xs:enumeration value="http://www.w3.org/TR/xmlschema-1/" />
      <xs:enumeration value="http://www.w3.org/TR/xmlschema-2/" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>



xs:pattern and xs:anyURI

File: Data.xml
<?xml version="1.0"?>
<Book xmlns="http://www.wbex.ru"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.wbex.ru Schema.xsd">
   http://www.wbex.ru
</Book>
File: Schema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.wbex.ru" 
  xmlns="http://www.wbex.ru"
  elementFormDefault="qualified">
  
    <xs:element name="Book" type="httpURI"/>
 
   
  <xs:simpleType name="httpURI">
    <xs:restriction base="xs:anyURI">
      <xs:pattern value="http://.*" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>