In XML technology, a document can be written to constrain the writing specification of an XML document, which is called an XML constraint.
A common constraint technology XML DTD; XML Schema.
XML Schema is also a schema language for defining and describing the structure and content of XML documents, and it appears to overcome the limitations of DTDs
XML Schema VS DTD:
XML schemas conform to the XML syntax structure.
XML APIs such as DOM, Sax can easily parse the contents of XML Schema documents.
XML schemas support namespaces very well.
XML Schemas support more data types than XML DTDs, and enable users to customize new data types.
The XML Schema defines constraints with a strong ability to make detailed semantic restrictions on XML instance documents.
XML Schemas cannot define entities as DTDs, and are more complex than DTDs, but XML Schemas are now the standard of the organization of the consortium, which is gradually replacing DTDs.
The DTD (document type definition), which is all called the documentation type definition.
The XML file uses the DOCTYPE declaration statement to indicate the DTD file it follows, and the DOCTYPE declaration statement has two forms:
First, when the referenced file is local, the following methods are used:
<! DOCTYPE Document root node SYSTEM "URL of DTD file" >
For example: <! DOCTYPE Bookshelf SYSTEM "Book.dtd" >. Write your handwriting in the XML file.
Second, when the referenced file is a public file, the following methods are used:
<! DOCTYPE Document root node Public "DTD name" "DTD file URL" >
DTD syntax: element definition, attribute definition, entity definition.
Declares an XML element--<! element element name elements type >
The element type can be element content, or type <! ELEMENT >
You can also use the +, *,?, and so on in the element content to indicate the number of times an element appears:
+: One or more times (book +)
?: 0 times or one time (book?)
*: 0 or more times (book *)
Tag attributes in an XML document need to be set by attlist
Syntax format:
<! attlist element name
Property Name 1 attribute value type setting description
Property Name 2 attribute value type setting description
......
>
Setup Description:
#REQUIRED: This property must be set
#IMPLIED: You can set or not set
#FIXED: Indicates that the value of this property is fixed to a value and that no other value can be set for the property in the XML file. But you need to provide this value for this property
Use default values directly: You can set this value in XML or do not set the property value. Use default values if no settings are set.
Common property value Types
CDATA: Indicates that the property value is a normal text string.
Enumerated
Id
ENTITY (Entity)
Entity definition:
An entity is used to create an alias for a section of content that can later be referenced in an XML document using an alias.
In the DTD definition, a <! The ENTITY ...> statement is used to define an entity.
Entities can be grouped into two types: reference entities and parameter entities.
Reference entities are used primarily in XML documents
Syntax format:
<! ENTITY entity name "Entity Content": Turn directly into entity content
Reference mode:
& Entity name;
In XML Schema technology, there is a professional term to describe this process, that is, to bind the elements of an XML Schema document to a namespace, and later XML files can tell the parsing engine through this URI (namespace), where the elements written in the XML document come from and who are bound by them.
The XML Schema file itself is an XML file, but its extension is usually. xsd.
An XML Schema document is often called a schema document (a constraint document), and an XML file that follows this document is called an instance document.
As with an XML file, an XML Schema document must have a root node, but the name of the root node is a schema.
After writing an XML Schema constraint document, it is often necessary to bind the elements declared in this file to a URI address.
In XML Schema technology, there is a professional term to describe this process, that is, to bind the elements of an XML Schema document to a namespace,
Later, the XML file can tell the parsing engine through this URI (namespace), where the elements written in the XML document come from and who are bound by them. In an XML schema, each constraint schema document can be assigned a unique namespace,
Namespaces are represented by a unique URI (uniform Resource Identifier, Uniform Resource Identifier).
When you write a label in an XML file, you can declare by namespace declaration (xmlns) that the currently written label comes from which schema constraint document.
In order to declare the exact location of the schema file it follows in an XML document, it is usually necessary to specify the root node in the XML document using the schemalocation attribute, for example:
<itcast: Bookshelf xmlns:itcast= "http://www.itcast.cn"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://www.itcast.cn book.xsd" >
SchemaLocation This property has two values. The first value is the namespace that needs to be used. The second value is the location of the XML schema used by the namespace, separated by a space.
Note that when you use the SchemaLocation property, you also need to specify where the property comes from.
Basic format:
Xmlns= "URI"