XML easy learning Manual (1): Quick Start to XML

Source: Internet
Author: User
Tags xml example


Preface
XML is getting hotter and hotter. The basic tutorial on XML is also available on the Internet. However, a lot of concepts and terms are often daunting. Many friends ask me: what is the use of XML? Do we need to learn it? I want to write a comprehensive introduction to my personal learning experience and experience. Article . First, there are two points to be affirmed:
First, XML must be the future development trend, whether it is a web designer or a network Program Personnel should learn and understand in time. Waiting will only lead to your loss of opportunities;
Second, new knowledge will certainly have many new concepts. You can only improve your understanding and acceptance. Don't be afraid and escape. After all, we are still young.

Outline

This article is divided into five parts. They are respectively XML Quick Start, XML concept, XML terminology, XML implementation, and XML instance analysis. At last, the appendix introduces the relevant XML resources. From the perspective of common web designers, the author tells you about all aspects of XML in plain and vivid language, helping you open the secrets of XML and quickly step into the new field of XML.

Chapter 1: XML Quick Start

1. What is XML?
2. Is XML a new concept?
3. What are the advantages of using XML?
4. Is XML hard to learn?
V. Differences between XML and HTML
Vi. Strict XML format
7. More information about XML
1. What is XML?
This is often the first question, and you may not understand the first question, because most of the textbooks answer this question:
XML is short for extensible markup language.
This is a standard definition. So what is a markup language and why is it extensibility? It is a bit confusing. I think it will be better to understand this:
You are very familiar with HTML. It is a markup language. Remember its full name: "hypertext markup language" hypertext markup language. Understand? At the same time, there are many tags in HTML, such as

Here are several confusing concepts to remind everyone:
1. XML is not a markup language. It is only used to create a markup language (such as HTML. Day, confused again! It doesn't matter. You only need to know this: XML and HTML are different. It is more useful than HTML. We will introduce it in detail later.
2. XML is not an alternative to HTML. XML is not an HTML upgrade. It is just a supplement to HTML and provides more functions for HTML extension. We will continue using HTML for a long period of time. (However, it is worth noting that the upgraded html version of XHTML is indeed moving closer to adapt to XML .)
3. You cannot use XML to directly write web pages. Even if XML data is contained, it must be converted to HTML format for display on the browser.

The following is an XML example document (Example 1) used to indicate the information in this document:

<? XML version = "1.0"?>
<Myfile>
<Title> XML Quick Start </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Myfile>

Note:
1. This section Code It's just code, which makes you understand XML at first, and does not implement specific applications;
2. the <title> and <author> statements are self-created tags. They are different from HTML tags. For example, <title> indicates the title of an article, <title> in HTML is the page title.
2. Is XML a new concept?
No. XML is derived from SGML, a markup language standard that is earlier than HTML.
For more information about SGML, you only need to have a general concept.
SGML stands for "Standard Generalized Markup Language ). Look at the name to know: it is the standard of the markup language, that is to say, all the Markup languages are developed according to SGML, of course, including HTML. SGML has a wide coverage. All files in a certain format belong to SGML, such as reports and music scores. html is the most common file format on the SGML network. Therefore, SGML is the "mother" of HTML ".
XML is a simplified version of SGML, but it only skips the complicated and uncommon parts. (Oh, see! Is the second "mother" in HTML. No wonder it is more powerful than HTML .), Like SGML, XML can also be applied in various fields such as finance and scientific research. Here we will talk about the use of XML in web.
Here, you should understand that XML is used to create a markup language similar to HTML, and then use this markup language to display information.
3. What are the advantages of using XML?
With HTML, why do we still need XML?
Because the network is more and more widely used, it is no longer necessary to handle ever-changing documents and data by simply using a single HTML file type, and the syntax of HTML itself is not strict, seriously affects network information transmission and sharing. (Think about how many designer brain cells are broken by browser compatibility issues .) People have already begun to explore how to meet the needs of various applications on the network. SGML can be used, but SGML is too large, complex programming, so the final choice of "Weight Loss" SGML---XML as the next generation of Web application of data transmission and interaction tools.
What are the advantages of using XML? Let's take a look at the W3C organization (XML standard setter) Description:
XML makes it easier to use the SGML language on the network "simple and direct": it simplifies the process of defining file types and simplifies the process of programming and processing SGML files, it simplifies transfer and sharing on the web.
1. XML can be widely used anywhere on the Web;
2. XML can meet the needs of network applications;
3. Using XML makes programming easier;
4. XML is easy to learn and create;
5. the XML code is clear and easy to read and understand;
Or abstract. Let's take a look at the powerful advantages of XML in subsequent instance tutorials!
4. Is XML hard to learn?
If you are interested in learning XML, you may ask: is XML difficult? What is the basis for learning XML?
XML is very simple and easy to learn. If you are familiar with HTML, you will find that its documentation is very similar to HTML. See the same example document (Example 1 ):

<? XML version = "1.0"?>
<Myfile>
<Title> XML Quick Start </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Myfile>

The first line <? XML version = "1.0"?> Is an XML declaration, indicating that the document follows the XML 1.0 specification.
The second line defines the first element in the document, also known as the root element: <myfile>. This is similar to the <HTML> Start mark in HTML. Note that this name is customized by yourself.
The following four sub-elements are defined: title, author, email, and date. The title, author, email address, and date of the article are described respectively. Of course, you can define these labels in Chinese to make it easier to understand:

<? XML version = "1.0" encoding = "gb2312"?>
<Article>
<Title> XML easy learning manual </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Article>

This is an XML document. Anyone familiar with HTML can directly write such a simple XML document.
In addition, to learn XML, you must master a Page scripting language. Common examples are Javascript and VB script. Because XML data uses scripts to implement calls and interactions in HTML. Let's take a simple example (Example 2):
1.save the following code as myfile.htm

<HTML>
<Head>
<Script language = "JavaScript" for = "window" event = "onLoad">
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. async = "false ";
Xmldoc. Load ("myfile. xml ");
Nodes = xmldoc.doc umentelement. childnodes;
Title. innertext = nodesitem (0). text;
Author. innertext = nodes. Item (1). text;
Email. innertext = nodes. Item (2). text;
Date. innertext = nodes. Item (3). text;
</SCRIPT>
<Title> call XML data in HTML </title>
</Head>
<Body bgcolor = "# ffffff">
<B> title: </B>
<Span id = "title"> </span> <br>
<B> author: </B>
<Span id = "author"> </span> <br>
<B> mailbox: </B>
<Span id = "email"> </span> <br>
<B> date: </B>
<Span id = "date"> </span> <br>
</Body>
</Html>

2. Save the following code as myfile. xml

<? XML version = "1.0" encoding = "gb2312"?>
<Myfile>
<Title> XML easy learning manual </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Myfile>

3. Put them in the same directory and open them in ie5 or a later browser to see the effect. Learn and master a script, and you will truly understand the powerful functions of XML.
V. Differences between XML and HTML
Both XML and HTML come from SGML. They both contain tags and have similar syntaxes. The biggest difference between HTML and XML is that HTML is a fixed markup language, it uses inherent tags to describe and display webpage content. For example, This is a qualitative difference: Web pages mix data and display, while XML separates data and display.
For example, in myfile.htm, We only care about the page display mode. We can design different interfaces and typeset pages in different ways, but the data is stored in myfile. XML.
(If you are a programmer, you will be surprised to find that this is very similar to the idea of Modular object-oriented programming! In fact, why is a Web page not a program ?)
The difference makes XML easy, efficient, and scalable in terms of network applications and information sharing. Therefore, we believe that XML, as an advanced data processing method, will bring the network to a new realm.
Vi. Strict XML format
Based on the lessons learned from the loose HTML format, XML insisted on implementing "good format" at the beginning ".
Let's first look at some HTML statements, which are everywhere in HTML:
1. <p> sample
2. <B> <I> sample </B> </I>
3. <TD> sample </TD>
4. <font color = Red> samplar </font>
In XML documents, the syntax of the preceding statements is incorrect. Because:
1. All tags must have an ending mark;
2. All XML tags must be reasonably nested;
3. All XML tags are case sensitive;
4. All marked attributes must be included in;
Therefore, the correct syntax of the preceding statement in XML is:
1. <p> sample </P>
2. <B> <I> sample </I> </B>
3. <TD> sample </TD>
4. <font color = "red"> samplar </font>
In addition, the XML tag must follow the following naming rules:
1. the name can contain letters, numbers, and other letters;
2. The name cannot start with a number or underscore;
3. The name cannot start with XML (or XML;
4. The name cannot contain spaces.

Any error in the XML document will produce the same result: the webpage cannot be displayed. Browser developers have reached an agreement to strictly and picky Parse XML, and any small error will be reported. You can modify myfile. xml above, for example, change <email> to <email>, and use ie5 to open myfile. xml directly. An error message page is displayed:

<? XML version = "1.0" encoding = "gb2312"?>
<Myfile>
<Title> XML easy learning manual </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Myfile>
7. More information about XML
Now you know:
1. What is XML;
2. Relationships and differences between XML, HTML, and SGML;
3. simple application of XML.
Congratulations! You no longer know nothing about XML, and are already at the forefront of network technology. The entire learning process does not seem very difficult :)
If you are more interested in XML and want to learn more about XML details and other practical technologies, please refer to our next chapter: The concept of XML. (Source: enet College)

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.