Chapter 2
Introduction to
XML ConceptsAfter the quick start study in Chapter 1, you already know that XML is a language that allows you to create your own tags. It can separate data and formats from web pages. It can store data and share data. The characteristics make XML omnipotent. If you want to learn XML in depth and systematically master the ins and outs of XML, then we must first return to the concept of XML. XML (Extensible Markup Language), an extensible markup language. "Extensibility" "Identity" "Language". Each word clearly points out the important features and functions of XML. Let's analyze it in detail:
1. Extensibility 2. Identification 3. Language 4. Structure 5. Meta data 6. Display 7. DOM
1. Extensibility --- Using XML, you can create your own tags for your documents ( tags).
The first word of XML is "expansibility", which is why XML has powerful functions and flexibility.
In HTML, there are many fixed tags that we must remember and then use. You cannot use tags that are not in the HTML specification. In XML, you can create any markup you need. You can give full play to your imagination and give your documents some memorable tag names. For example, if your document contains some game guides, you can create a tag named <game>, and then create <RPG>, <SLG> and other tags under <game> according to the game category. You can create any number of markers as long as they are clear and easy to understand.
You may not adapt to it at first, because when we learn HTML, there are fixed tags that can be learned and used directly; (many people, including myself, build their own web pages while analyzing other people's codes and logos), while XML But there is no markup to learn, and few documents have exactly the same markup. What should we do? Haha, if not, just create it yourself. Once you actually start writing XML documents, you'll find that it's fun to create new tags as you like. You can create your own unique markup and even create your own HTML language.
Scalability gives you more choices and powerful capabilities, but it also creates a problem: you must learn to plan. You need to understand your own document, know what parts it consists of, the relationship between them and how to identify them.
There is one more thing to note about establishing a logo. The logo describes the type or characteristics of the data, such as <width>, age <age>, name <name>, etc., rather than the content of the data, such as: <10pxl>, <18>, < Zhang San>, these are useless marks. If you have studied databases, you can understand it this way, an identifier is a field name.
2. Identification---Using XML you can identify elements in the document.
The second word of XML is "identification", which shows that the purpose of XML is to identify elements in the document.
Whether you are using HTML or XML, the essence of tags is to facilitate understanding. If there is no tag, your document will appear to the computer as just a long string, and every word will look the same, with no emphasis.
Through tags, your document is easier to read and understand. You can divide it into paragraphs and list titles. In XML, you can take advantage of its extensibility to create more appropriate tags for documents.
However, one thing to remind everyone: the logo is only used to identify information, it does not convey information itself. For example, this HTML code:
<b>frist step<b>
Here <b> means bold. It is only used to indicate that the "frist step" characters are displayed in bold. <b> itself does not contain any actual information. You cannot see <b> on the page, which really conveys the information. is the "frist step".
3. Language---When using XML, you have to follow a specific syntax to identify your documents.
The third word of XML is "language". This shows that as a language XML must follow certain rules. Although XML's extensibility allows you to create new identities, it still must follow a specific structure, syntax, and clear definitions.
In the computer field, language often refers to a "programming language", which is used to program to implement some functions and applications. However, not all "languages" are used for programming. XML is just a language used to define identification and describe information. Language.
Let's take a deeper look at the basic principles of XML application. It may be boring, but it is important for the overall understanding. You can go through it quickly first to have a vague concept in your mind. The specific essence needs to be practiced. Take your time to understand.
4. Structure--XML promotes the structure of documents.
"Structure" sounds too abstract. As we understand it, structure is to establish a framework for your document. , just like writing an outline first. Structuring makes your document look less disorganized, and each part is closely connected to form a whole.
Structuring has two principles:
1. Every part (every element) is related to other elements. The associated series form the structure.
2. The meaning of the logo itself is separated from the information it describes.
Let's look at a simple example to help understand:
<?xml version="1.0" encoding="GB2312"?>
<myfile>
<title>XML Easy Learning Manual</title>
<chapter>XML Quick Start
<para>What is XML</para>
<para>Benefits of using XML</para>
</chapter>
<chapter>The concept of XML
<para>Extensibility</para>
<para>Logo</para>
</chapter>
</myfile>
This is the XML description document of this article. You can see that the identification is divided into three levels of association, which is very clear:
<myfile>
<chapter>
<para>
...
</para>
</chapter>
</myfile>
The above document structure is also called a "document tree". The backbone is the parent element, such as <myfile>, and the branches and pages are child elements, such as <chapter> and <para>.
5. Meta data (Metadata)---Professional XML users will use meta data to work.
In HTML, we know that meta tags can be used to define keywords, introductions, etc. of web pages. These tags will not be displayed on the web page, but can be searched by search engines and affect the order of search results.
XML deepens and expands this principle. With XML, you can describe where your information is. You can verify the information through meta, perform searches, force display, or process other data.
The following are some uses of XML metadata in practical applications:
1. Digital signatures can be verified to make online business submissions valid.
2. Can be easily indexed and searched more efficiently.
3. Can transfer data between different languages.
The W3C organization is studying a metadata processing method called RDF (Resource Description Framework), which can automatically exchange information. The W3C claims that using RDF combined with digital signatures will enable "authentic and trustworthy" e-commerce on the network.
6. Display
Pages cannot be displayed using XML alone. We use formatting technology, such as CSS or XSL, to display documents created by XML tags.
We mentioned in Chapter 1 that XML separates data and format. The XML document itself does not know how to display it, and there must be auxiliary files to help achieve it. (XML cancels all tags, including font, color, p and other style definition tags, so XML uses a method similar to CSS in DHTML to define document styles.), the file type used to set the display style in XML
Thereare
:
1.
It itself is also based on XML language. Using XSL, you can flexibly set the document display style, and the document will automatically adapt to any browser and PDA (handheld computer).
XSL can also convert XML into HTML, so that older browsers can also browse XML documents.
2.CSS
Everyone is familiar with CSS. Its full name is Cascading Style Sheets, which is currently the main method used to display XML documents on browsers.
3.Behaviors
Behaviors have not yet become a standard. It is a unique feature of Microsoft's IE browser. You can use it to set some interesting actions on XML tags.
7.
DOM The full name of DOM is document object model. What is DOM used for? Assuming 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.
The object-oriented thinking method has become very popular. In programming languages (such as java, js), object-oriented programming ideas are used. In XML, the web page is to be operated and controlled as an object. We can create our own objects and templates. To communicate with objects and how to command objects, you need to use API. The full name of API is Application Programming Interface, which is the rule for accessing and operating objects. DOM is an API that describes the rules of HTML/XML document objects in detail. It specifies the naming convention, program model, communication rules, etc. of HTML/XML document objects. In an XML document, we can think of each identification element as an object --- it has its own name and attributes.
XML creates identifiers, and the role of DOM is to tell script how to operate and display these identifiers in the browser window
. We have briefly talked about some basic principles of XML. Let's take a look at the relationship between them and how they work. Yes, take a look at this picture first:
1.XML describes data types. 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 controls how elements act. For example: when a title element is "out of stock", it will be displayed in red.
4.DOM provides a common platform for the communication of scripts and objects, and displays the results in the browser window.
If any part is wrong, you will not get the correct result.
Okay, seeing this, we already have an overall general idea of how XML works. Through the study of this chapter, we may feel that XML seems to be more biased towards data processing and is more convenient for programmers to learn. The actual situation is also the same. The purpose of XML design is to conveniently share and interact data. In the next chapter, we will systematically understand various terms about XML. You are welcome to continue browsing.