The basic structure of XML [XML] and XML-Schema Constraint

XML

Brief introduction

In February 1998, W3C formally approved the Extensible Markup Language standard definition, extensible markup language can be structured documents and data, which can be exchanged between departments, customers and suppliers, to achieve dynamic content generation, enterprise integration and application development. Extensible Markup Language allows us to more accurately search for content, more easily transfer content to better describe things.

What are the scalable markup language?

  • Can be extended markup language is a lot like HTML markup language.
  • It is designed to transmit data rather than displaying data.
  • Its label is not predefined. You need to define your own labels.
  • It is designed to be self-descriptive.
  • It is a W3C Recommendation.

May expand the difference between the markup language and HTML

  • It's not super substitute text markup language.
  • It is a supplement to the HTML.
  • It Hypertext Markup Language designed for different purposes:
    - it is designed to transmit and store data, which is the focus of the content data.
    - HTML was designed to display data, which is an external focal point data.
  • HTML is designed to display information; and XML is designed to transmit information, which is independent of software and hardware information transfer tool.

May expand Markup Language is a W3C Recommendation

  • XML on February 10, 1998 became a W3C Recommendation.

Everywhere can expand Markup Language

  • XML is the most commonly used tools for transferring data between various applications.

basic structure

Ado, direct line and the code:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 人力资源管理系统 -->
<hr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="hr.xsd">
    <employee no="007">
        <name>或无言</name>
        <age>18</age>
        <salary>20000</salary>
        <department>
            <dname>开发部</dname>
            <address>XX大厦-B103</address>
        </department>
    </employee>
    <employee no="008">
        <name>张三</name>
        <age>31</age>
        <salary>30000</salary>
        <department>
            <dname>工程部</dname>
            <address>XX大厦-B104</address>
        </department>
    </employee>
</hr>
  • version = "1.0" encoding = "UTF-8": description of the XML version number and coding scheme.
  • xmlns: xsi: Description This document is a schema constraint.
  • xsi: noNamespaceSchemaLocation: the name specified schema file.
  • hr: root tag of this human resource management system documentation.
  • hr, employee, name, age, department and other labels are their own definition, make up the structure of the document.
  • Tag is a property, such as no = "007", the semantics of this document in the number of employees.

XML Schema

definition

Its role is to define legally constituted group of an XML document, like document type definition (language abbreviation: DTD ) role as an XML Schema defines:

  • Elements can appear in a document of;
  • Property in the document may appear;
  • Those elements are sub-elements;
  • Order and number of sub-elements;
  • If an element can contain text or blank;
  • Elements and attributes of data types;
  • The default and fixed values ​​for elements and attributes;

basic structure

The above text XML document as an example, it may be a structure of Schema:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="hr">
        <complexType>
            <sequence>
                <element name="employee" minOccurs="1" maxOccurs="9999">
                    <complexType>
                        <sequence>
                            <element name="name" type="string"></element>
                            <element name="age">
                                <simpleType>
                                    <restriction base="integer">
                                        <minInclusive value="18"></minInclusive>
                                        <maxInclusive value="60"></maxInclusive>
                                    </restriction>
                                </simpleType>
                            </element>
                            <element name="salary" type="integer"></element>
                            <element name="department">
                                <complexType>
                                    <sequence>
                                        <element name="dname" type="string"></element>
                                        <element name="address" type="string"></element>
                                    </sequence>
                                </complexType>
                            </element>
                        </sequence>
                        <attribute name="no" type="string" use="required"></attribute>
                    </complexType>
                </element>
            </sequence>
        </complexType>
    </element>
</schema>

XML Schema looks and looks like, and it is also written by the XML, XML document that describes the structure , in the Schema not define your own tags and attributes.

  • element name = "hr": hr declare a name for the root node.
  • complexType: complex node, you must use this label contain child nodes.
  • sequence: sequence, all child nodes under strict order of writing.
  • minOccurs = "1" maxOccurs = "9999": the current node appears at least once appeared 9,999 times.
  • type = "integer": allow only integer numbers.
  • simpleType: constraint simple types.
  • restriction base = "integer": defining allowed only integer numbers.
  • minInclusive value = "18": 18 Min.
  • attribute name = "no" type = "string" use = "required": the definition of property, where there is no constraint employee element must this property.

to sum up

Young people, listen to me an advise, we must learn English, or the same as the definition of variables have to check with my word! (Of course, I'm also working ...)

references:

https://baike.baidu.com/item/%E5%8F%AF%E6%89%A9%E5%B1%95%E6%A0%87%E8%AE%B0%E8%AF%AD%E8%A8%80?fromtitle=xml&fromid=86251

https://baike.baidu.com/item/XML%20Schema

Guess you like

Origin www.cnblogs.com/huowuyan/p/11200465.html