DTD and XML Schema

Source: Internet
Author: User
Tags float double

What is a valid XML document?
If an XML document specifies the DTD or schema of its document type and data structure and is associated with it, and the validation is correct.

Use DTD to define XML elements <! Element element name element content declaration>

Expression symbol and its definition:
() Is used to group elements | select a number of + 1-N times * 0-N times in the listed objects? 0-1, appears sequentially

Element content type:
Empty empty flag any element content # pcdata any character data other type

Use DTD to define attributes of XML elements <! ATTLIST element name attribute type default value>

Attribute type and its meaning:
CDATA can only contain the unique entity of character data IDs. Entities declared in the Entities document but not analyzed
Nmtoke and nmtokens are a subset of CDATA. They must contain letters, numbers, periods, passbooks, underscores, or colons.
Notation (enumerated) Notation (beauty | beast)
Enumerated enumeration (1 | 2 | 3 | 4 ...)

Four forms of default attribute values # required cannot be blank # mplied can be blank # fixed value must be the default value of defaultvalue in the value specified for listing

Association between TDT and XML
1. Internal DTD <! Doctype name [...]
2. External DTD <! Doctype root element name system "dtd_url"
3. Public dish DTD <! Doctype root element name public "DTD name" "dtd_url"]

Use DTD to define XML entities <! Entity write "Jan Egil">
External entity <! Entity Write System "http...">

Namespace: xmlns: [prefix] = "[namespace url]"

Limitations of DTD:
1. DTD does not comply with XML syntax 2. DTD cannot be expanded 3. DTD does not support namespace applications 4. DTD does not provide powerful data type support and can only represent simple data types

Schema

Features: 1. fully Based on XML syntax 2. it can be used to process XML. 3. greatly expanded the Data Type 4. support prototype, that is, inherit 5. support Attribute Group 6. multiple schemas can be used in an XML document.

Pre-defined type string Boolean decimal float double duration represents the duration datetime represents the specific time date hexbinary hexadecimal anyurl notation type

Schema elements are mainly divided into simple types and complex types, which can only contain characters of simple types, and other complex types.

The schema document uses <schema> as its root element.

Element tags in the schema document
Schema element attribute simpletype complextype group attributegroup simplecontent choice list Union unique squence Restriction

Define simple type elements <XSD: element name = "element name" type = "type"/>
Define complex type elements <XSD: element name = "element name"> <XSD: complextype> <XSD: sequence> ordered
Using the ref element, you can direct it to another module to make the document more readable.
Defines the number of identical child elements masoccurs = "unbounded" borderless minoccurs
Define an optional sub-element <XSD: Choice> A | B?
Custom type <XSD: Restriction base = "XD: string"> <XSD: Pattern value = "Regular Expression"/>
Enumeration type <XSD: Restriction base = "XD: string"> <XSD: enumeration value = ""/>

Define attributes:
<XSD: attribute name = "ID" type = "XSD: string"/>
Property optional use = "required" required is required value optional is optional value prohibited is no Attribute Value
Define default value default = "1"

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.