Chapter 2 XML concepts
Introduction
After the Quick Start in chapter 1, you know that XML is a language that allows you to create your own identifiers. It can separate the data and format from the web page, it can store and share data so that XML is omnipotent. If you want to learn XML in depth and understand the ins and outs of XML, we should first go back to the concept of XML. XML (Extensible Markup Language), a scalable identifier Language. "Scalability" identifier "language ". Each word clearly identifies the important features and functions of XML. Let's analyze it carefully:
I. scalability
Ii. Identification
Iii. Language
4. Structured
V. Meta data
6. Display
VII. DOM
I. scalability-using XML, you can create your own tags for your document ).
The first word of XML is "scalability", which is why XML is powerful and flexible.
There are many fixed tags in HTML. We must remember and use them. You cannot use tags not in HTML specifications. In XML, you can create any tag you need. You can make full use of your imagination and give your documents some memorable markup names. For example, your document contains some game strategies. You can create a tag named <game> and then <RPG> under <game>, <SLG>. As long as it is clear and easy to understand, you can create any number of tags.
At first, you may not be able to adapt, because we can directly learn and use fixed tags when learning HTML. (many people, including myself, analyze others' codes and identifiers, but XML does not have any markup to learn, and few documents are exactly the same. What should we do? You can create it yourself. Once you really start writing XML documents, you will find it interesting to create new tags as you like. You can create tags with your own characteristics, or even your own HTML language.
Scalability gives you more options and powerful capabilities, but it also produces a problem that you must learn to plan. You need to understand your documents, know what components it consists of, the relationships between them, and how to identify them.
To create an identity, you must also note that the identity describes the data type or characteristics, such as <width>, age <age>, and name <name>, rather than the data content. For example: <10pxl>, <18>, <Zhang San>, these are useless tags. If you have learned the database, you can understand that the identifier is a field name.
Ii. Identification-you can use XML to identify the elements in the document.
The second word of XML is "identifier", which indicates that XML is intended to identify elements in the document.
Whether you are HTML or XML, the essence of the identifier is easy to understand. If there is no identifier, your document is just a long string on the computer, and each word looks the same, there are no key points.
By logo, your documents are easy to read and understand. You can divide paragraphs and list titles. In XML, you can use its scalability to create a more appropriate identifier for the document.
However, one thing to note is that the identifier is only used to identify information, and it does not convey information. For example, the following HTML code:
<B> frist step <B>
Here, <B> indicates bold. It is only used to show the "frist step" character in bold. <B> it does not contain any actual information, you cannot see <B> On the page. The actual message is "frist step ".
3. Language --- use XML to identify your documents according to specific syntax.
The third word of XML is "language ". This indicates that XML must follow certain rules as a language. Although the scalability of XML allows you to create new identifiers, it must still follow the specific structure, syntax, and clear definitions.
In the computer field, languages often represent one? Quot; language ", used for programming to implement some functions and applications, but not all" languages "are used for programming. XML is just a language used to define the identification and description information.
Next, let's take a closer look at the basic principles of XML applications, which may be boring, but the overall understanding is very important. You can try it again first, there is a vague concept in mind, and the specific essence needs to be understood slowly in practice.
4. Structured --- XML promotes document structuring. All information is arranged in a certain link.
"Structured" sounds too abstract. In this way, structuring is to create a framework for your document, just as writing an outline first. The structure makes your documents look like they are not disorganized, and each part is closely linked to form a whole.
There are two principles for structuring:
1. Each part (each element) is associated with other elements. The associated series form a structure.
2. The meaning of the identifier is separated from the information it describes.
Let's look at a simple example to help us understand:
<? Xml version = "1.0" encoding = "GB2312"?>
<Myfile>
<Title> XML easy learning manual </title>
<Chapter> Quick Start to XML
<Para> what is XML </para>
<Para> advantages of using XML </para>
</Chapter>
<Chapter> XML Concept
<Para> scalability </para>
<Para> id </para>
</Chapter>
</Myfile>
This is the XML Description document in this article. It can be seen that the identifiers are associated in three levels, which is very clear:
<Myfile>
<Chapter>
<Para>
...
</Para>
</Chapter>
</Myfile>
The above document structure is also called the "Document Tree". The trunk is the parent element, such as <myfile>. The branches and pages are child elements, such as <chapter> and <para>.
5. Meta data-professional XML users use meta data to work.
In HTML, we know that meta identifiers can be used to define keywords and descriptions of webpages. These identifiers are not displayed on webpages, but can be searched by search engines, the sorting order of search results is also affected.
XML has deepened and extended this principle. With XML, you can describe where your information is. You can use meta to verify information, perform search, and force display, or process other data.
The following describes the usage of XML metadata in practical applications:
1. The digital signature can be verified to make the online business submission action (submission) Valid.
2. You can easily create indexes and perform more effective searches.
3. data can be transmitted between different languages.
The W3C organization is working on a metadata processing method named "Resource Description Framework", which can automatically exchange information. W3C claims that it uses RDF in combination with digital signatures, this will enable "authentic and trusted" e-commerce in the network.
6. Display
The page cannot be displayed in XMl alone. We use formatting technology, such as CSS or XSL, to display the document created by the XML tag.
In the first chapter, we mentioned that XML separates data from format. The XML document itself does not know how to display it. It must have auxiliary files for implementation. (XML removes all the identifiers, including font, color, p, and other Style definition identifiers. Therefore, XML uses CSS methods similar to DHTML to define Document Style styles .), The following file types are used to set the display style in XML:
1. XSL
XSL stands for Extensible Stylesheet Language, which is the main file type for designing XML document display styles in the future. It is also based on the XML language. With XSL, You can flexibly set the document display style. The document will automatically adapt to any browser and PDA (handheld computer ).
XSL can also convert XML into HTML, so that the old browser can also browse XML documents.
2. CSS
CSS is familiar to everyone. Cascading Style Sheet is currently the main method used to display XML documents in a browser.
3. Behaviors
Behaviors has not yet become a standard. It is a unique feature of Microsoft's IE browser. It can be used to set some interesting actions for XML tags.
VII. DOM
The full name of DOM is document object model. What is DOM used? Assume that your document is treated as a separate object. DOM is the standard for how to operate and control this object using HTML or XML.
Object-oriented ideas and methods have become very popular. In programming languages (such as java and js), they all use object-oriented programming ideas. In XML, the webpage is also used as an object for Operation and Control. We can create our own objects and templates. To communicate with objects, you need to use APIs to command objects. The full name of the API is Application Programming Interface, which is the rule for accessing and operating objects. DOM is an API that describes the object rules of HTML/XML documents in detail. It specifies naming conventions, program models, and communication rules for HTML/XML document objects. In XML documents, we can think of every identifier element as an object-it has its own name and attributes.
The DOM is used to tell the script how to operate and display these identifiers in the browser window.
We have briefly described some basic principles of XML above. Let's take a look at the associations between them and how they work. Here is a figure:
1. XML describes the data type. For example, "King lear" is a title element;
2. CSS stores and controls the display style of elements. For example, the title will be displayed in 18pt font.
3. script scripts control how elements act. For example, when the title element "out of stock" is displayed in red.
4. DOM provides a public platform for scripting and object communication, and displays the results in the browser window.
If an error occurs in any part, no correct result is returned.
Now, we have a general idea about how XML works. Through this chapter, we may feel that XML seems to be more inclined to data processing, making it easier for programmers to learn. This is also the case. The purpose of the XML design is to facilitate data sharing and interaction. In the next chapter, we will systematically understand various terms about XML. You are welcome to continue browsing.