DTD and schema bound by different constraints

Benpian notes understand ------ Schema syntax constraints

      ------ W3school can refer to the Schema tutorial.

Schema: XML-based alternative to DTD, XML document structure used to describe. Support for XML namespaces ----- xmlns-- abbreviation of XML namespace .

     XML Schema language is also referred to as XML Schema definitions (XML Schema Definition, XSD).

     Therefore, schema file extension .xsd , which itself is an XML file.

 

Note: XML Schema is a set of xml elements and attributes W3c predetermined create these elements and attributes define the structure and content model xml document.

   When you declare a <Schema> documents, you must begin with an XML declaration , which is the root node is <Schema>.

    You must declare several properties in the root node:

xmlns: xsi = "http://www.w3.org/2001/XMLSchema" - represents a statement of the current XML file as a constraint file, use Schema elements and data types, attributes from this namespace.

  targetNamespace property  ------ setting the constraint document unique identification , usually set to the equivalent URL path --- ID number, by the attribute value can be introduced constraint file.

     elementFormDefault property : Two values  qualified  and  unqualified,

        When the value of qualified ---- represents a sub-element must use the namespace prefix --- aliases         

        When the value is expressed unqualified ---- child elements do not have to use an alias namespace prefix ---   

Schema file declares:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/company"
elementFormDefault="qualified">

   Introducing Schema constraint file in XML instance files:

      In the XML file on the root node define some attributes:

Generally the -instance modified namespace declared ------ xsi  xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" - represents an instance of the xml file 

xmlns: namespace prefix = "targetNamespace attribute value" ----- constraint file corresponds to the introduction, can be introduced into a plurality Schema files.

  Namespace prefix corresponding to the package name, the name of the same method different packet (label) is not the same nature. 

       Difficult to understand:  xsi: schemaLocation attribute : used to declare a target namespace of the schema document

            xsi: noNamespaceSchemaLocation attributes : mode for documents no target namespace, the property value is a single value, just specify the location of schema documents.

    schemaLocation attribute value --------- composed of a pair of URI. The first is the name of a namespace URI, between the two separated by whitespace URI, given the position of the second URI of .xsd schema document. Mode processor document reading mode from this position, the target namespace of the schema document must match the first URI. XML Schema recommendation pointed out, xsi: schemaLocation attribute in the instance can use on any element, but not necessarily the root element , however, xsi: schemaLocation attribute must appear before any elements and attributes it to be verified, so the schemaLocation in the namespace appear to be declared before using xmlns.    

xsi: noNamespaceSchemaLocation property: a reference model for the document does not target namespace, the property value is a single value ---- position to specify the mode of the document.

 

      Understood as a process: in the instance document, we can many times with the introduction of multiple namespaces xmlns attribute , but the namespace introduced must address the source of the namespace and namespace declaration introduced in the schemaLocation attribute effective , this property belongs to - iNSTANCE modified instance document attributes, of which, we use a different namespace prefixes to distinguish different namespace. The different namespaces are predefined attributes, rules of grammar tags and labels and the like. For example: Students set up a namespace name tag, teacher namespace also set up a name tag, then this time, when the two bound document is introduced into the same XML instance documents, how to distinguish? The name tag in the end should follow the student or teacher namespace name space? By providing a different prefix, in use of the tag, setting the prefix.

      It can in turn be understood only if the value of the schemaLocation attribute take effect when the previous xmlns attribute to take effect.

            

XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<company xmlns = "http://www.example.org/company"
xmlns:dept="http://www.example.org/department"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/company    company.xsd 
            http://www.example.org/department department.xsd
" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Define a namespace ------------- xmlns namespace prefix equivalent alias ---- xsi namespace URI of the ---- HTTP: // www.w3.org/2001/XMLSchema -instance the XML file allows the definition of a plurality of reference files Schema constraints, distinguished by a different namespace prefixes

 XML Schema role:

     Definitions may appear in a document element
     definitions may appear in the document attributes
     define which element is a child element of
     the defined order of child elements
     defined number of sub-elements
     define the elements and attributes of the data type
     definitions and element default attribute value and the fixed value

 

    Simple elements : only contains text, does not contain any other elements and attributes - <element name = "xxx" type = " data type" /> --- Schema pre-defined data types.

    Complex elements : element comprises sub-elements or attributes

<XS: Element name = " LastName " type = " XS: String " /> // --- tag name indicates the name of the data type represents the type of tag values 
<XS: Element name = " Age " type = " XS: Integer " />     

XML Schema provides four configuration packet to indicate the sequence of sub-elements :      

  <sequence>: expressed sequence requires each member of the sequence of packets of the same order of occurrence defined in the instance document. By the number of occurrences maxOccursand minOccurscontrol.

  <All>: use all element group definition, all elements in the group members can occur once or not occur, and the element may appear in any order

  <choice>: choice of DTD corresponds packet "|", when the sub-elements are combined into a choice, only one of these elements must appear in the element instance document, for the case where mutually exclusive.

  <Group> groups: group packet is declared several elements grouped, a group to incorporate them as a complex type definition.

<xsd:element name="电影" type="演员"/>
    <xsd:complexType name="演员">
        <xsd:sequence>
            <xsd:group ref="主演"/>
            <xsd:element name="片名" type="类型"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="类型">
        <xsd:choice>Chinese"
            <xsd: Element name =" type="string"/>
            <xsd:element name="英文" type="string"/>
        </xsd:choice>
    </xsd:complexType>
    <xsd:group name="主演">
        <xsd:sequence>
            <xsd:element name="男主演" type="string"/>
            <xsd:element name="女主演" type="string"/>
        </xsd:sequence>
    </xsd:group>
</xsd:schema

 

 Disclaimer property : All properties are declared as simple types.

  <XS: attribute name = " XXX " type = " yyy " /> 
  <-! name attribute refers to the name, type refers to a type of attribute data ->

 

  In XML Schema file, built-in (pre-defined) multiple data types and tags, which can be attributes ----------- defining the content, and the content ----- finger elements (tags), content attributes are defined, such as: a type of value must be like.

     In XML Schema files can be both complex and simple elements set limit, and are pre-set limits for the label.

   The following is a complex value ------ types including subelements and attributes value

       There is no simple element subelements and attributes of the label content ----- only limit it.

<xsd: Element name = " movie " > 
        <xsd: complexType> 
            <xsd: Sequence> 
                <xsd: Element name = " title " of the type = " xsd: String " /> 
                <xsd: Element name = " starring " of the type = " starring type " /> 
                <xsd: Element name = " issuance " > 
                    <xsd: complexType> 
                        <xsd: Sequence> 
                            <xsd:name = Element " number " of the type = "xsd: Integer " /> 
                            <xsd: Element name = " Release date " of the type = " xsd: String " /> 
                            <xsd: Element name = " issuing country " of the type = " xsd: String " /> 
                            <xsd: Element name = " number of copies " type = " number type " /> 
                        </ XSD: Sequence> 
                    <XSD: complexType> 
                </ XSD: Element> 
            </ XSD:sequence>sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:simpleType name="主演类型">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="6"/>
            <xsd:maxLength value="20"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="数量类型">
        <xsd:restriction base="xsd:integer">
            <xsd:minInclusive value="1"/>
            <xsd:maxInclusive value="10000"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

 

     

XML Schema data types:

Built-in data type (built-in data types)

The basic data types (Primitive Data Types)

Extended data types (Deriverd Data Types)

User-defined data types (defined by simpleType)

      Complex type (defined by the complexType)

  

XML Schema and DTD constraint constraint compared:

    DTD constraints can only reference one, while Schema constraints can reference more

    DTD data types is limited, and a variety of data types Schema, including custom data types

    DTD and xml with their own special syntax and schema follows the xml syntax

    DTD can not be extended and does not support command space

    DOM and SAX parsing easier way to resolve schema

 

 

     Reference Notes: Bloggers' quack chick "------- https: //blog.csdn.net/u010161630/article/details/52829371

 

Guess you like

Origin www.cnblogs.com/Tanggula-pioneer/p/11772084.html
DTD