search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Home Backend Development XML/RSS Tutorial XML easy learning general section

XML easy learning general section

Dec 23, 2016 am 11:50 AM
xml

Foreword

XML is becoming more and more popular, and basic tutorials on XML can be found everywhere on the Internet. However, a lot of concepts and terms are often daunting. Many friends asked me: What is the use of XML? Do we need to learn it? I want to write a more comprehensive introduction article based on my personal learning process and experience. First of all, there are two points that need to be affirmed:

First: XML is definitely the future development trend. Whether you are a web designer or a network programmer, you should learn and understand it in time. Waiting will only make you lose opportunities;

Second Two: There will definitely be many new concepts in new knowledge. Only by trying to understand and accept them can you improve. Don't be afraid and run away, after all we are still young.

Outline

This article is divided into five parts. They are XML quick introduction, XML concepts, XML terminology, XML implementation, and XML example analysis. The final appendix introduces XML-related resources. The author stands from the perspective of ordinary web designers and uses plain and vivid language to tell you all aspects of XML, helping you to lift the mystery of XML and quickly enter the new field of XML.

Chapter 1: Quick Start with XML

1. What is XML?

2. Is XML a new concept?

3. What are the benefits of using XML?

4. Is XML difficult to learn?

5. The difference between XML and HTML

6. The strict format of XML

7. More about XML

1. What is XML?


This is often the first question, and you often don’t understand it on the first question, because most textbooks answer this:

XML is the abbreviation of Extensible Markup Language, an extensible markup language. . This is the standard definition. So what is a markup language and why is it called extensibility? It's already a bit confusing. I think it would be better to understand it this way:

You are already very familiar with HTML. It is a markup language. Do you remember its full name: "Hypertext Markup Language". Understood? At the same time, there are many tags in HTML, such as, etc., which are standardized and defined in HTML
4.0, and XML allows you to create such tags yourself, so it is called extensibility.

Here are a few confusing concepts to remind everyone:

1.XML is not a markup language. It is just a metalanguage used to create markup languages ​​(such as HTML). God, I'm confused again! It doesn't matter, you just need to know this: XML and HTML are different, and its uses are much wider than HTML, which we will introduce in detail later.

2.XML is not a replacement for HTML. XML is not an upgrade of HTML, it is just a supplement to HTML, extending more functions to HTML. We will continue to use HTML for a long time to come. (But it is worth noting that XHTML, the upgraded version of HTML, is indeed moving closer to adapting to XML.)

3. You cannot use XML to write web pages directly. Even if it contains XML data, it still needs to be converted into HTML format before it can be displayed on the browser.

The following is an XML sample document (Example 1), used to represent the information of this article:

<myfile><br><br>

<title>XML Quick Start</title><br&gt ;<br>

<author>ajie</author><br><br>

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

&lt ;date>20010115</date><br><br>

</myfile>


Note:


1. This code is just code to give you a preliminary understanding of XML, and it cannot What specific applications can be achieved;

2. Statements like < title>, < author> are self-created tags. They are different from HTML tags. For example, < title> here means the title of the 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.

Let’s take a brief look at SGML. You only need to have a general idea.

The full name of SGML is "Standard Generalized Markup Language". You can tell just by looking at the name: it is a standard for markup languages, which means that all markup languages ​​are developed in accordance with SGML, including HTML, of course. SGML has a wide coverage. All files with a certain format belong to SGML, such as reports, music scores, etc. HTML is the most common file format of SGML on the Internet. Therefore, people jokingly call SGML the "mother" of HTML.


XML is a simplified version of SGML, except that the complex and uncommon parts are omitted. (Oh, I understand! It is the second "mother" of 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. What we are talking about here is just the application of XML in the web. Just the application.


At this point, you should have a little understanding: XML is used to create and define a markup language similar to HTML, and then use this markup language to display information. 3. What are the benefits of using XML?

With HTML, why do we need to use XML?

Because network applications are becoming more and more widespread, it is no longer enough to rely on a single file type of HTML to handle ever-changing documents and data. Moreover, the grammar of HTML itself is very loose, which seriously affects the transmission and sharing of network information. (Think about how many designers’ brain cells have been damaged by browser compatibility issues.) People have already begun to explore ways to meet the needs of various applications on the Internet. It is possible to use SGML, but SGML is too large and complicated to program, so I finally chose the "weight-loss" SGML---XML as the data transmission and interaction tool for next-generation web applications.


What are the benefits of using XML? Let’s look at the description from the w3c organization (XML standard setter):

XML makes using the SGML language on the Internet more "simple and direct": It simplifies the process of defining file types, simplifies the process of programming and processing SGML files, and simplifies the process of defining file types. Delivery 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 will make programming easier;

4.XML is easy to learn and create;

5.XML code will be clear and easy to read and understand;

It is still a bit abstract. Let us slowly experience the powerful advantages of XML in the following example tutorials!

4. Is XML difficult to learn?

If you are interested in learning XML, you can’t help but ask: Is XML difficult? What kind of foundation is needed to learn XML?

XML is very simple and easy to learn. If you are familiar with HTML, you will find that its documents are very similar to HTML, look at the same sample document (Example 1):

?xml version="1.0"?><br><br>

< myfile><br><br>

<title>XML Quick Start</title><br><br>

<author>ajie</author><br><br>

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

<date>20010115</date><br><br>

</myfile>

The first line is an XML declaration, indicating that the document follows the XML version 1.0 specification.

The second line defines the first element (element) in the document, also called the root element: < myfile>. This is similar to the < HTML> opening tag in HTML. Note that this name is defined arbitrarily by yourself.

Four sub-elements are defined below: title, author, email, and date. Indicate the title, author, email address and date of the article respectively. Of course, you can define these tags in Chinese, which makes them 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. Any netizen who knows HTML can directly write such a simple XML document.

In addition, to learn XML, you must also master a page scripting language, the most common ones are javascript and VB script. Because XML data uses script to implement calling and interaction in HTML. Let’s look at the simplest 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.documentElement.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>Calling XML data in HTML</title>

</head>

< body bgcolor="#FFFFFF">

<b>Title: </b>

<span id="title"> </span>

<b>Author: </ b>>

<span id="author"></span>

<b>Email: </b>

<span id="email"></span&gt ;

<b>Date:</b>

<span id="date"></span>

</body><br><br>

</html><br><br>
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, open them with IE5 or above browser, you can see the effect . Learn and master a script, and you will truly understand the extremely powerful functions of XML.

5. The difference between XML and HTML


Both XML and HTML come from SGML. They both contain tags and have similar syntax. The biggest difference between HTML and XML is that HTML is a stereotyped markup language that uses inherent tags. Markup to describe and display the content of the web page. For example, < H1> represents the first line of title and has a fixed size. In contrast, XML has no fixed tags. XML cannot describe the specific appearance and content of a web page. It only describes the data form and structure of the content.


This is a qualitative difference: web pages mix data and display, while XML separates data and display.


Let’s look at the example above. In myfile.htm, we only care about the display mode of the page. We can design different interfaces and layout the page in different ways, but the data is stored in myfile.xml, no need any changes.


(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, isn’t a web page a program?)


It is this difference that makes XML stand out on the Internet Application and information sharing are convenient, efficient and scalable. Therefore, we believe that XML, as an advanced data processing method, will bring the network to a new realm.


6. The strict format of XML


Drawing on the lessons learned from the loose format of HTML, XML has insisted on implementing "good format" from the beginning.

Let’s first look at some statements in HTML, which can be found everywhere in HTML:

1.

sample


2.
3.< td>sample< /TD>


4.< font color=red>samplar< /font>


In the XML document, the syntax of the above statements is wrong. Because:

1. All tags must have a corresponding closing tag;

2. All XML tags must be nested reasonably;

3. All XML tags are case-sensitive;

4. All The attributes of the tag must be enclosed in "";

So the correct way to write the above statement in XML is

1.

sample


2.< b>< i>sample< /i>< /b>


3.< td>sample< /td>


4.< font color="red">samplar< /font>


  In addition, XML tags must follow the following naming rules :

1. The name can contain letters, numbers and other letters;

2. The name cannot start with numbers or "_" (underscore);

3. The name cannot start with the letters xml (or XML or Xml..) Beginning;

4. The name cannot contain spaces.

Any error in the XML document will result in the same result: the web page cannot be displayed. Browser developers have reached an agreement to implement strict and picky parsing of XML, and any small errors will be reported. You can modify the myfile.xml above, for example, change < email> to < Email>, and then open myfile.xml directly with IE5, you will get an error message page:


<?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 about XML

Okay, by now you already know:

1. What It is XML;

2. The relationship and difference between XML, HTML, and SGML;

3. Simple application of XML.

The above is the content of the general chapter on easy learning of XML. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

JSON vs. XML: Why RSS Chose XML JSON vs. XML: Why RSS Chose XML May 05, 2025 am 12:01 AM

RSS chose XML instead of JSON because: 1) XML's structure and verification capabilities are better than JSON, which is suitable for the needs of RSS complex data structures; 2) XML was supported extensively at that time; 3) Early versions of RSS were based on XML and have become a standard.

RSS in XML: Decoding Tags, Attributes, and Structure RSS in XML: Decoding Tags, Attributes, and Structure Apr 24, 2025 am 12:09 AM

RSS is an XML-based format used to publish and subscribe to content. The XML structure of an RSS file includes a root element, an element, and multiple elements, each representing a content entry. Read and parse RSS files through XML parser, and users can subscribe and get the latest content.

Understanding RSS Documents: A Comprehensive Guide Understanding RSS Documents: A Comprehensive Guide May 09, 2025 am 12:15 AM

RSS documents are a simple subscription mechanism to publish content updates through XML files. 1. The RSS document structure consists of and elements and contains multiple elements. 2. Use RSS readers to subscribe to the channel and extract information by parsing XML. 3. Advanced usage includes filtering and sorting using the feedparser library. 4. Common errors include XML parsing and encoding issues. XML format and encoding need to be verified during debugging. 5. Performance optimization suggestions include cache RSS documents and asynchronous parsing.

Building XML Applications with C  : Practical Examples Building XML Applications with C : Practical Examples May 03, 2025 am 12:16 AM

You can use the TinyXML, Pugixml, or libxml2 libraries to process XML data in C. 1) Parse XML files: Use DOM or SAX methods, DOM is suitable for small files, and SAX is suitable for large files. 2) Generate XML file: convert the data structure into XML format and write to the file. Through these steps, XML data can be effectively managed and manipulated.

RSS, XML and the Modern Web: A Content Syndication Deep Dive RSS, XML and the Modern Web: A Content Syndication Deep Dive May 08, 2025 am 12:14 AM

RSS and XML are still important in the modern web. 1.RSS is used to publish and distribute content, and users can subscribe and get updates through the RSS reader. 2. XML is a markup language and supports data storage and exchange, and RSS files are based on XML.

XML in C  : Handling Complex Data Structures XML in C : Handling Complex Data Structures May 02, 2025 am 12:04 AM

Working with XML data structures in C can use the TinyXML or pugixml library. 1) Use the pugixml library to parse and generate XML files. 2) Handle complex nested XML elements, such as book information. 3) Optimize XML processing code, and it is recommended to use efficient libraries and streaming parsing. Through these steps, XML data can be processed efficiently.

Beyond Basics: Advanced RSS Features Enabled by XML Beyond Basics: Advanced RSS Features Enabled by XML May 07, 2025 am 12:12 AM

RSS enables multimedia content embedding, conditional subscription, and performance and security optimization. 1) Embed multimedia content such as audio and video through tags. 2) Use XML namespace to implement conditional subscriptions, allowing subscribers to filter content based on specific conditions. 3) Optimize the performance and security of RSSFeed through CDATA section and XMLSchema to ensure stability and compliance with standards.

Understanding RSS: An XML Perspective Understanding RSS: An XML Perspective Apr 25, 2025 am 12:14 AM

RSS is an XML-based format used to publish frequently updated content. 1. RSSfeed organizes information through XML structure, including title, link, description, etc. 2. Creating RSSfeed requires writing in XML structure, adding metadata such as language and release date. 3. Advanced usage can include multimedia files and classified information. 4. Use XML verification tools during debugging to ensure that the required elements exist and are encoded correctly. 5. Optimizing RSSfeed can be achieved by paging, caching and keeping the structure simple. By understanding and applying this knowledge, content can be effectively managed and distributed.

Related articles