XML Easy Learning Manual (4)

Source: Internet
Author: User
Tags contains manual insert version
Xml

Two. Terminology relating to DTDs

What is a DTD, which we have already mentioned briefly above. DTDs are an efficient way to ensure that XML documents are well-formed, comparing XML documents and DTD files to see if documents conform to specifications, and whether elements and tags are used correctly. A DTD document contains: Defining rules for elements, defining rules for relationships between elements, attributes that can be used by elements, entities that can be used, or symbolic rules.

The DTD file is also an ASCII text file with a suffix named. dtd. For example: Myfile.dtd.

Why use a DTD file? My understanding is that it satisfies network sharing and data interaction, and the greatest advantage of using DTDs is the sharing of DTD files. (This is the public attribute in the DTD description statement above). For example, people from different parts of the same industry use the same DTD file as the document creation specification, so their data can be easily exchanged and shared. There are other people on the web who want to supplement the data, and only need to build the document based on the common DTD specification, and you can join it immediately.

At present, there are already a large number of written DTD files available. For different industries and applications, these DTD files have established common elements and tagging rules. You don't need to re-create yourself, just add the new logo you need on their basis.

Of course, if you want, you can create your own DTD, which may work better with your documents. It's also easy to build your own DTD, which typically requires only 4-5 elements to be defined.

There are two ways to invoke a DTD file:

1. DTDs directly contained within XML documents

You just have to insert some special instructions in the DOCTYPE statement, like this:

We have an XML document:

<?xml version= "1.0" encoding= "GB2312"?>

<myfile>

<title>xml Easy Learning Handbook </title>

<author>ajie</author>

</myfile>

We'll insert the following code after the first line: -->

<! DOCTYPE MyFile [

<! ELEMENT title (#PCDATA) >

<! ELEMENT author (#PCDATA) >

<! ENTITY Copyright "Copyright 2001, Ajie." >

]>

2. Invoke a standalone DTD file

Save the DTD document as a. dtd file and call it in the DOCTYPE declaration line, for example, save the following code as MYFILE.DTD

<! ELEMENT MyFile (title, author) >

<! ELEMENT title (#PCDATA) >

<! ELEMENT author (#PCDATA) >

It is then invoked in an XML document and inserted after the first line:

<! DOCTYPE myfile SYSTEM "MYFILE.DTD" >

We can see that the DTD document is similar to the invocation of JS in HTML, about how the DTD document is written, and we'll introduce the syntax of the XML document in the next chapter.

Let's look at the terminology related to DTDs:

1.Schema (Planning)

A schema is a description of a data rule. Schema does two things:

A. It defines the relationship between element data types and elements;

B. It defines the type of content that an element can contain.

A DTD is a schema of XML documents.

2.Document Trees (document tree)

The document tree, as we've already mentioned in the second chapter, is an image representation of the hierarchical structure of document elements. A document structure tree contains the root element, which is the top-level element (the first element immediately after the XML declaration statement). See Example:

<?xml version= "1.0"?>

<filelist>

<myfile>

<title>...</title>

<author>...</author>

</myfile>

</filelist>

The example above is arranged in a three-level structure in the form of a "tree", where <filelist> is the root element. In both XML and DTD files, the first definition is the root element.

3.Parent element (parent Element)/child element (child elements)

A parent element is an element that contains other elements, and the contained elements are called its child elements. Look at the "structure tree" above, where <myfile> is the parent element,<title>,<author> is its child element, and <myfile> is the child element of <filelist>. Like <title> this does not contain any child elements of the last level of the element we also call "page elements."

4.Parser (Analytic software)

Parser is a tool software that checks whether an XML document follows a DTD specification.

The parser of XML is developed into two categories: one is the "unacknowledged class Paeser", which detects whether the document adheres to XML syntax rules, and whether the document tree is established with the element identity. The other is "validation class Paeser", which detects not only the document syntax, the structure tree, but also the specification of the element ID you use to comply with the corresponding DTD file.

Parser can be used independently or as part of an editing software or browser. In the following list of related resources, I list some of the parsers that are currently popular.

Well, through chapter three, we've learned some basic terms for XML and DTD, but we don't know how to write these files, what syntax we need to follow, and the next chapter will focus on the syntax for composing XML and DTD documents.



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.