Outline:
Introduction
1. Terms related to XML documents
2. Terms related to DTD
Introduction
The most troublesome thing for beginners to learn XML is that there are a lot of new terminology concepts. understand. Since XML itself is also a brand-new technology, it is constantly developing and changing. Organizations and major network companies (Microsoft, IBM, SUN, etc.) are constantly introducing their own insights and standards, so it is not surprising that new concepts are flying everywhere. . There is no authoritative institution or organization in China to officially name these terms. Most of the Chinese textbooks you see about XML are translated based on the author's own understanding. Some are correct and some are wrong, which further hinders the development of XML. Our understanding and learning of these concepts.
The explanation of XML terms you will see below is also the author’s own understanding and translation. Ajie is based on the XML1.0 standard specification released by the W3C organization and related official documentation. It can be ensured that these understandings are basically correct, at least not wrong. If you want to read and understand further, I have listed the sources and links to relevant resources at the end of this article, which you can access directly. Okay, let’s get to the point:
1. Terms related to XML documents
What is an XML document? You know the HTML source code file? An XML document is an XML source code file written with XML tags. XML documents are also ASCII plain text files that you can create and modify using Notepad. The suffix name of XML documents is .XML, for example, myfile.xml. You can also directly open the .xml file using IE5.0 or above browsers, but what you see is the "XML original code" and the page content will not be displayed. You can try saving the following code as myfile.xml:
XML document contains three parts:
1. An XML document declaration;
2. A definition of the document type;
3. Content created with XML tags.
Example:
QUICK START OF XML The line
is the declaration of an XML document. The second line indicates that this document uses filelist.dtd to define the document type. The following line is the main part of the content.
Let’s learn about the relevant terms in XML documents:
1.Element (element):
We already know something about elements in HTML. It is the smallest unit that makes up an HTML document, and it is the same in XML. An element is defined by a tag, including the start and end tags and the content inside, like this:
The only difference is: in HTML, the tag is fixed, while in In XML, tags need to be created yourself.
2.Tag (logo)
Tag is used to define elements. In XML, tags must appear in pairs, surrounding the data. The name of the identifier is the same as the name of the element. For example, such an element:
where
3.Attribute:
What is an attribute? Look at this HTML code:
word. Among them, color is one of the attributes of font.
Attributes are further descriptions and explanations of the logo. A logo can have multiple attributes, such as the font attribute and size. Attributes in XML are the same as attributes in HTML. Each attribute has its own name and value. The attribute is part of the identifier. Example:
Attributes in XML are also defined by yourself. We recommend that you try not to use attributes and change attributes into sub-elements. For example, the above code can Change it to this:
The reason is that attributes are not easy to expand and be manipulated by programs.
4.Declaration
In the first line of all XML documents there is an XML declaration. This declaration indicates that this document is an XML document and which XML version specification it follows. An XML declaration statement looks like this:
5.DTD (Document Type Definition)
DTD is used to define elements, attributes and elements in XML documents relationship between.
You can check whether the structure of the XML document is correct through the DTD file. But creating an XML document does not necessarily require a DTD file. Detailed descriptions of DTD files will be listed separately below.
6.Well-formed XML (well-formed XML)
A document that abides by XML syntax rules and adheres to XML specifications is called "well-formed". If all your markup strictly adheres to the XML specification, then your XML document does not necessarily need a DTD file to define it.
A well-formed document must start with an XML declaration, for example:
where you must state that the document adheres to The XML version is currently 1.0; secondly, it indicates that the document is "independent", and it does not require a DTD file to verify whether the identification in it is valid; thirdly, it is necessary to indicate the language encoding used in the document. The default is UTF-8. If you use Chinese, you need to set it to GB2312.
A well-formatted XML document must have a root element, which is the first element created immediately after the declaration. Other elements are child elements of this root element and belong to a group of root elements.
The content of a well-formed XML document must comply with XML syntax when written. (We will explain XML syntax in detail in the next chapter)
7. Valid XML (valid XML)
An XML document that abides by XML syntax rules and complies with the corresponding DTD file specifications is called a valid XML document. Note that we compare "Well-formed XML" and "Valid
XML". The biggest difference between them is that one fully complies with the XML specification and the other has its own "Document Type Definition (DTD)".
The process of comparing and analyzing an XML document with its DTD file to see if it complies with DTD rules is called validation. This process is usually handled by a software called parser.
A valid XML document must also start with an XML declaration, for example:
Different from the above example, In the standalone (independent) attribute, "no" is set here because it must be used with the corresponding DTD. The DTD file is defined as follows:
Among them:
"!DOCTYPE" means you want to define a DOCTYPE;
"type-of-doc" is the name of the document type, which is defined by you. It is usually the same as the DTD file name;
Only use one of the two parameters "SYSTEM/PUBLIC". SYSTEM refers to the URL of the private DTD file used by the document, while PUBLIC refers to the URL of the public DTD file used by the document.
"dtd-name" is the URL and name of the DTD file. All DTD files have the suffix ".dtd".
We still use the above example, it should be written like this:
The above is the content of XML terminology. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!