DTD and schema

Source: Internet
Author: User
Tags processing instruction

After several days of study, I have a certain understanding of XML, and I have used some XML before. So far, you can simply use XML to access data.

This part of the XML video focuses on some basic XML knowledge.

Including: XML basic format requirements, entity reference, attributes, Processing Instruction Pi, and basic syntax rules

Entity reference: the entity reference mainly solves the problem of special characters. Some characters are used but given specific meanings by XML itself. At this time, we need to use entity references.

For example, we know that all the tags in XML are in the form of "<>", so replace & lt, & gt when we need such characters. This is the reference.

The entity reference here is a little different from the entity reference in our programming language. It feels like a constant.

 

Processing indication Pi: PI (Processing
Instruction) is used to command the parsing engine to parse XML document content. Must start with "<?" Starting with "?>" As the end, XML declaration statements are the most common processing commands. Simply put, the processing indication is to tell the program what kind of style or standard to read data, or the XML document is stored according to that style or standard!

 

The following content focuses on DTD and schema.

DTD: Document Type Definition

It is a syntax rule about a tag. It is a validation mechanism for XML files and is part of an XML file, but not required. DTD is an effective method to ensure that the XML document format is correct. You can compare the XML document and DTD file to see whether the document complies with the specifications, and whether the elements and labels are correctly used. The XML file provides an application data exchange format. The DTD makes the XML file a data exchange standard.

DTD can be divided into internal DTD and external DTD.

The internal DTD is included in the source XML document. An environment with a verification mechanism will judge whether the XML is consistent based on the DTD rules in the document.

For example

<? Xmlversion = "1.0"?>

<! Doctypenote [

<! Elementnote (to, from, heading, body)>

<! Elementto (# pcdata)>

<! Elementfrom (# pcdata)>

<! Elementheading (# pcdata)>

<! Elementbody (# pcdata)>

]>

<Note>

<To> Tove </to>

<From> Jani </from>

<Heading> reminder

<Body> don 'tforget me this weekend </body>

</Note>

The external DTD, that is, the DTD is located outside the XML source file and is encapsulated in
Doctype definition.

For example

This is the "note. DTD" file containing the DTD:

<! Elementnote (to, from, heading, body)>

<! Elementto (# pcdata)>

<! Elementfrom (# pcdata)>

<! Elementheading (# pcdata)>

<! Elementbody (# pcdata)>

When using:

<? Xmlversion = "1.0"?>

<! Doctypenote System "note. DTD">

<Note>

<To> Tove </to>

<From> Jani </from>

<Heading> reminder

<Body> don 'tforget me this weekend! </Body>

</Note>

The external DTD includes the system and public keywords to indicate the location of the DTD file.

The system keyword indicates that the document uses a private DTD file, which is similar to the company's rules and regulations, but only observed by the company's internal staff.

The public keyword is used for the common DTD. The "DTD name" is called a public identifier. It is like the Rules and Regulations jointly issued by multiple companies. Every company must abide by them.

Using DTD, we can verify whether our data meets our own needs; whether the data received from external programs meets our requirements; and the two organizations can use a standard DTD to exchange data.

 

The schema function is similar to the DTD function, but the schema is superior in the current web development environment. Because it is a valid XML document, you can understand the XML structure more intuitively. In addition, the schema supports namespaces, multiple simple and complex built-in data types, and custom data types. With so many advantages, schema has gradually become a unified specification for XML applications.

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.