Easy Learning Handbook (3) XML terminology

Source: Internet
Author: User
Tags date define definition contains insert numeric value version valid

Chapter III Terms of XML

Introduction

The most troubling thing about learning XML is that there is a whole bunch of new terminology concepts to understand. Since XML itself is a new technology, is evolving and changing, organizations and major network companies (Microsoft, Ibm,sun, etc.) are constantly introducing their own ideas and standards, so the new concept flying in the sky is not surprising. And the lack of authoritative institutions or organizations in the country to formally naming these terms, you see the Chinese textbooks on XML are mostly based on the author's own understanding of translation, some are correct, some are wrong, even more hinder our understanding of these concepts and learning.

The explanation of the XML terms you will see below is also an understanding and translation of the author itself. Atzie is based on the XML1.0 standard specification issued by the Organization of international organizations and the relevant official documentation. Can ensure that these understandings are basically correct, at least not wrong. If you want to read and understand further, I have listed in the last section of this article the source and link of related resources, you can visit directly. Okay, let's turn to the point:

I. Terminology relating to XML documents

What is an XML document? Know HTML original code file, XML document is XML ID write XML original code file. XML documents are also plain text files in ASCII, which you can create and modify with Notepad. The XML document has a suffix named. xml, such as Myfile.xml. With IE5.0 or above, you can also open the. xml file directly, but what you see is "XML source code" without displaying the page content. You can try to save the following code as a myfile.xml:

The following are the referenced contents:

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

<myfile>

<title>xml Easy Learning Handbook </title>

<author>ajie</author>

<email>ajie@aolhoo.com</email>

<date>20010115</date>

</myfile>

The XML document contains three parts:

1, an XML document declaration;

2, a definition of the type of document;

3, the content created with the XML identity.

An example is provided:

The following are the referenced contents:

<?xml version= "1.0"?>

<! DOCTYPE filelist SYSTEM "FILELIST.DTD" >

<filelist>

<myfile>

<title>quick START of Xml</title>

<author>ajie</author>

</myfile>

......

</filelist>

Where the first line of <?xml version= "1.0"?> is a declaration of an XML document, the second line shows that the document is defined with FILELIST.DTD, and the third line is the content body part.

Let's take a look at the relevant terminology in an XML document:

1, Element (elements)

element in HTML we already know that it is the smallest unit that makes up HTML documents, as well as in XML. An element is defined by an identity, including the start and end identities and the contents thereof, like this:<author>ajie</author>

The only difference is that in HTML the identity is fixed, and in XML, the identity needs to be created by yourself.

2, Tag (logo)

Identity is used to define an element. In XML, the identity must appear in pairs, enclosing the data in the middle. The name of the identity and the name of the element are the same. For example such an element:

<author>ajie</author>

Where <author> is the logo.

3, attribute (attributes)

What is an attribute? Look at this HTML code: <font color= "Red" >word</font>. Where color is one of the properties of font.

A property is a further description and description of the identity, and an identity can have multiple properties, such as font properties and size. The attributes in the XML are the same as those in HTML, each of which has its own name and numeric value, and the attribute is part of the identity. Example:

<author sex= "female" >ajie</author>

The attributes in XML are also defined by themselves, and we recommend that you try not to use attributes and change the attributes to child elements, such as the code above can be changed like this:

The following are the referenced contents:

<author>ajie

<sex>female</sex>

</author>

The reason is that attributes are not easy to expand and are manipulated by programs.

4, Declaration (statement)

There is an XML declaration in the first line of all XML documents. This declaration indicates that the document is an XML document and it follows the specification of which XML version. An XML declaration statement is like this:

<?xml version= "1.0"?>

5. DTD (file type definition)

DTDs are used to define the relationships between elements, attributes, and elements in an XML document.

The DTD file allows you to detect the correctness of the structure of an XML document. However, creating an XML document does not necessarily require a DTD file. For a detailed description of the DTD file we will list the items separately below.

6, well-formed XML (well-formed XML)

A document that adheres to XML syntax rules and adheres to XML specifications is called a "good format". If all your logos are strictly XML compliant, your XML document does not necessarily need a DTD file to define it.

A well-formed document must start with an XML declaration, such as:

<?xml version= "1.0" standalone= "yes" encoding= "UTF-8"?>

Where you have to explain the XML version of the document, which is currently 1.0, and then the document is "standalone", it does not require a DTD file to verify that the identity is valid, and third, to describe the language encoding used in the document. The default is UTF-8, if you use Chinese, you need to set to GB2312.

A well-formed XML document must have a root element, which is the first element that is created immediately after the declaration, and the other elements are child elements of the root element, and belong to a group of root elements.

The contents of a well-formed XML document must be written with XML syntax. (We'll explain the XML syntax carefully in the next chapter)

7. Valid XML (valid XML)

An XML document that adheres to the XML syntax rules and complies with the appropriate DTD file specification is called a valid XML document. Note that we compare "well-formed XML" with "Valid xml", and the biggest difference is that one is fully compliant with the XML specification and one has its own "file type definition (DTD)".

The process of comparing an XML document with its DTD file to see if it conforms to the DTD rule is called validation (confirm). Such processes are usually handled through a software called parser.

A valid XML document must also start with an XML declaration, such as:

<?xml version= "1.0" standalone= "no" encode= "UTF-8"?>

Unlike the example above, in the standalone (standalone) attribute, this setting is "no" because it must be used with the corresponding DTD, and the DTD file is defined as follows:

<! DOCTYPE type-of-doc system/public "Dtd-name" >

which

"! DOCTYPE "means you want to define a DOCTYPE;

"Type-of-doc" is the name of the document type, defined by yourself, usually the same as the DTD file name;

The two parameters of "System/public" are only one. System refers to the Web address of the private DTD file used by the document, while public refers to the URL of the document calling a common DTD file.

"Dtd-name" is the URL and name of the DTD file. The suffix for all DTD files is ". DTD".

Let's use the example above to write this:

<?xml version= "1.0" standalone= "no" encode= "UTF-8"?>

<! DOCTYPE filelist SYSTEM "FILELIST.DTD" >

Ii. 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, directly contained in the XML document DTD

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

We have an XML document:

The following are the referenced contents:

<?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:

The following are the referenced contents:
<! 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

The following are the referenced contents:

<! 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 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:

The following are the referenced contents:

<?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 (parents)/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. Please continue browsing, thank you!



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.