Learn XML (II) --XSD

XML Schema Definitions
  • <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:dw="http://www.ibm.com/developerWorks/"
        elementFormDefault="unqualified"
        attributeFormDefault="unqualified" version="4.0">
Elements and attributes
  • element, annotation, complexType, choice, type
Simple types
  • <xsd:element name="text-data" type="xsd:string" />
Extending base types
  • restrictionn
    <xsd:simpleType name="colorname">
      <xsd:restriction base="xsd:string">
        <xsd:enumeration value="blue" />
        <xsd:enumeration value="green" />
        <xsd:enumeration value="red" />
      </xsd:restriction>
    </xsd:simpleType>
  • extentioin
    <xsd:element name="title">
      <xsd:complexType>
        <xsd:simpleContent>
          <xsd:extension base=" xsd:string">
            <xsd:attribute name="isbn" type="xsd:string"/>
          </xsd:extension>
        </xsd:simpleContent>
      </xsd:complexType>
    </xsd:element>
Generating XML Schemas from Instance Documents
  • relaxer -xsd toc.xml
Generating XML Schemas from a DTD
  • install dtd2xs from [url]www.lumrix.net[/url]
  • setup CLASSPAHT
  • java dtd2xsd toc.dtd > toc-schema.xsd
Validating XML Against an XML Schema
  • nonnamespaced
    <dw-document xsi:noNamespaceSchemaLocation="dw-document-4.0.xsd"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  • namespaced
    <dw-document xmlns="http://www.ibm.com/developerWorks"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.ibm.com/developerWorks
                          dw-document-4.0.xsd">
  • Validating against a schema
    xmllint --schema dw-document-4.0.xsd index.xml --noout



















發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章