Home  >  Article  >  Backend Development  >  An introductory tutorial on the basic concepts and syntax of XML markup language (picture)

An introductory tutorial on the basic concepts and syntax of XML markup language (picture)

黄舟
黄舟Original
2017-03-10 20:04:261791browse

This article mainly introduces the basic concepts and syntax introductory tutorial of XML markup language. XML is also widely used to mark data as XML data exchange format. Friends in need can refer to it


XML stands for Extensible Markup Language. It is a text-based markup language derived from the Standard Generalized Markup Language (SGML).

XML tags identify data and are used to store and organize data, rather than specifying how to display it, like HTML for displaying data. XML won't replace HTML in the near future, but it introduces possibilities by adopting many of the successful features found in HTML.

Here are three important characteristics of XML that make it useful for a wide variety of systems and solutions:

XML is extensible: XML allows us to create our own suitable applications A self-describing tag or language for a program.
XML carries data, but does not render it: XML allows us to store data regardless of how it will be rendered.
XML is a public standard: XML was developed by an organization called the World Wide Web Consortium (W3C), and it is available as an open standard.


Purposes of XML
This short list of uses for XML says it all:

XML can work behind the scenes to simplify the creation of HTML documents for large websites .
XML can be used to exchange information between organizations and systems.
XML can be used to unload and reload the database.
XML can be used to store and organize data, and can also customize data processing requirements.
XML It's easy to incorporate stylesheets to create almost any desired output.
In fact, any type of data can be represented as an XML document.


What are tags?
XML is a markup language that defines a set of rules for encoding documents in a human-readable and machine-readable format. So what exactly is a markup language? Markup is information added to a document that improves its meaning in some way. It identifies parts and how they relate to each other. More specifically, a markup language is a set of symbols that can be placed into the text of a document to divide and mark certain parts of the document.

The following example shows what an XML tag embedded in a block of text looks like:

<message>
    <text>Hello, world!</text>
</message>

This fragment contains markup symbols, or tags, such as e2daf579f45d6c6feb003011d37ca22e and 28f128881ce1cdc57a572953e91f7d0f... 273e21371c5d5e701d3c98517a0bfa41. The tags 761b5f615852937c78510c6ee32be47a and dc97c94abba54b3574a1f2a9fcb1679b represent the beginning and end of this XML snippet. The tags 28f128881ce1cdc57a572953e91f7d0f and 273e21371c5d5e701d3c98517a0bfa41 wrap the text Hello world!.

Is XML a programming language?
A programming language used to create computer programs consists of syntax rules and its own vocabulary. These programs instruct the computer to perform specific tasks. XML does not qualify as a programming language because it does not perform any calculations or algorithms. It is usually stored in a simple text file and processed by special software capable of interpreting XML.

XML syntax
The following is a complete XML document:

<?xml version="1.0"?>
<concat-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</concat-info>

You can notice that there are two types in the above example Information:

tag, such as a544f4562fd2b177be55ff2b68d8d27b.
Text or character data, such as _Tutorials Point and (011) 123-4567_.
The following figure describes the syntax rules for writing different types of tags and text in XML documents:
An introductory tutorial on the basic concepts and syntax of XML markup language (picture)

Let's take a closer look at each component in the above figure:

XML Declaration
XML documents can have an optional XML declaration. It can be written in the following form:

<?xml version="1.0" encoding="UTF-8"?>


Here version is the XML version, and encoding specifies the character encoding used in the document.

Syntax rules for XML declaration

XML declaration is case-sensitive and must start with "8a82eb472d64dd53782fcc091813a312", where "xml" is lowercase .
If the document contains an XML declaration, it must be the first statement in the XML document.
The XML declaration must be the first statement of the XML document.
You can use an HTTP protocol to override the encoding value specified in the XML declaration.


Tags and elements
The structure of an XML file consists of several XML elements, also called XML nodes or XML tags. The name of an XML element is enclosed in angle brackets 6d267e5fab17ea8bc578f9e7e5e1570b as follows:

<element>

Syntax rules for tags and elements

Element syntax: Each XML element must be closed or With start and end elements, like this:

<element>....

or abbreviated form, like this:

<element/>

Element nesting: An XML element can contain multiple XML elements as Its child elements, but child elements cannot overlap. For example, an element's closing tag must have the same name as the most recently matched opening tag.

The following example shows incorrect nested tags:

<?xml version="1.0"?>
<contact-info>
<company>TutorialsPoint   
<contact-info>
</company>

The following example shows correct nested tags:

<?xml version="1.0"?>
<contact-info>
<company>TutorialsPoint</company>
<contact-info>

Root element: An XML document has only one root element. For example, the following is an incorrect XML document because the x and y elements appear at the top level without a root element:

<x>...</x>
<y>...</y>

下面的例子展示了正确形式的 XML 文档:

<root>
    <x>...</x>
    <y>...</y>
</root>

区分大小写: XML 元素的名称区分大小写。这意味着元素的起始和结束标签大小写必须一样。

例如 1e8dc3c754664c0739affa4dcf5121d9 和 __fe1be558c355044dbdab775b569281ef 就不同。

属性
attribute 使用名/值对给元素指定一个属性(property)。一个 XML 元素可以有一个或多个属性(attributes)。例如:

<a href="http://www.php.cn/">Tutorialspoint!</a>

这里 href 就是属性名称,而 http://www.php.cn/ 就是属性值。

XML 属性的语法规则

XML 属性名区分大小写(和 HTML 不一样)。也就是说 HREF 和 href 会被认为是两个不同的 XML 属性。
在语法中相同的属性不能有两个。下面的例子展示了不正确的语法,因为属性 b 被指定了两次:

<a b="x" c="y" b="z">....</a>

属性名定义不带引号标记,而属性值必须显示在引号标记中。下面的例子演示了不正确的 XML 语法:

<a b=x>....</a>

在上面的语法中,属性值没有定义在引号标记中。

XML 引用
引用 通常允许我们在 XML 文档中添加或包含附加的文本。引用始终以符号 "&" 开始,这是一个保留字符,以符号 ";" 结尾。XML 中有两种类型的引用:

实体引用: 一个实体引用的起始和结束定界符之间包含一个名称。比如 &,其中 amp 就是名称。这个 name 通常指向一个预定义的文本字符串或标记。

字符引用: 这些包含引用比如 A 包含一个 hash 标记("#"),后面紧跟一个数字。这个数字始终指向一个字符的 Unicode 码。在这里,65 指向字母 "A"。

XML 文本
XML 元素和 XML 属性的名称区分大小写。这意味着元素的开始和结束标签大小写必须一致。
为了避免字符编码的问题,所有的 XML 文件都应该保存为 Unicode UTF-8 或者 UTF-16 文件。
空白字符,比如空格,制表符以及 XML 元素和 XML 属性之间换行符会被忽略。
有些字符是 XML 语法本身保留的。因此,不能直接使用它们。要使用它们,就要使用一些替代实体。下面列出了一些:
An introductory tutorial on the basic concepts and syntax of XML markup language (picture)


The above is the detailed content of An introductory tutorial on the basic concepts and syntax of XML markup language (picture). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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