Home Backend Development XML/RSS Tutorial Detailed introduction to the use and learning of xml syntax

Detailed introduction to the use and learning of xml syntax

Mar 30, 2017 pm 01:46 PM

The syntax rules of

XML are simple and strict, making it very easy to learn and use.

Because of this, it is relatively easy to write software that reads and manipulates XML.

-------------------------------------------------- ------------------------------------

An example of an XML document
XML documents use a self-describing and simple syntax.

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Lin</to>
<from>Ordm</from>
<heading>Reminder</heading>
<body>Don&#39;t forget me this weekend!</body>
</note>
Copy after login

Line 1 of the document: XML declaration - defines the version of the XML standard that this document conforms to, in this case version 1.0 of the standard, using ISO-8859-1 (Latin-1 /West European)Character set.

The 2nd line of the document is the root element (like saying "This document is a note"):

<note>
Copy after login

The 3rd--6th line of the document describes the four elements of the root element. Child nodes (to, from, heading, and body):

<to>Lin</to>
<from>Ordm</from>
<heading>Reminder</heading>
<body>Don&#39;t forget me this weekend!</body>
Copy after login

The last line of the document is the end of the root element:

</note>
Copy after login

You can tell from this document that this is Ordm left a note for Lin? Can we not admit that XML is a beautiful self-describing language?

---------------------------------------- ---------------------------------------

All XML documents must There is a closing tag
In an XML document, it is illegal to omit the closing tag.

In HTML documents, some elements may not have closing tags. The following code is completely legal in HTML:

<p>This is a paragraph
<p>This is another paragraph
Copy after login

However, there must be a closing tag in the XML document, like the following example:

<p>This is a paragraph</p>
<p>This is another paragraph</p>
Copy after login

Note: You may have noticed, The first line in the above example does not have a closing tag. This is not a mistake. Because the XML declaration is not part of the XML document, it is not an XML element, and there should be no closing tag.

-------------------------------------------------- ------------------------------------

XML tags are case-sensitive
This is not the same as HTML, XML tags are case-sensitive.

In XML, the tag and the tag are two different tags.

Therefore, the capitalization of the opening tag and the closing tag in the XML document must be consistent.

<Message>This is incorrect</message>   //错误的
<message>This is correct</message>     //正确的
Copy after login

--------------------------------------------- ----------------------------------------

All XML elements must be reasonably included
Incorrect nested includes are not allowed in XML.

In HTML, some incorrect inclusions are allowed. For example, the following code can be parsed by the browser:

<b><i>This text is bold and italic</b></i>
Copy after login

In XML, all elements must have correct nested inclusions. The above code It should be written like this:

<b><i>This text is bold and italic</i></b>
Copy after login

------------------------------------------------ --------------------------------------------------

All XML documents must have a root element
The first element in the XML document is the root element.

All XML documents must contain a single tag to define, and all other elements must be nested in pairs within the root element. XML documents have and can only have one root element.

All elements can have child elements, and the child elements must be correctly nested in the parent element. The following code can illustrate it vividly:

<root>
<child>
<subchild>.....</subchild>
</child>
</root>
Copy after login

-------- -------------------------------------------------- -----------------------

AttributeThe value must be quoted ""
In XML, the element Attribute values ​​without quotes are illegal.

Like HTML, XML elements can also have attributes. Attributes of XML elements appear in name/value pairs. The XML syntax specification requires that XML element attribute values ​​must be quoted. Look at the two examples below, the first is wrong and the second is right.



<to>Lin</to>
<from>Ordm</from>
<heading>Reminder</heading>
<body>Don&#39;t forget me this weekend!</body>
</note>
Copy after login


Tove
Jani
Reminder
Don't forget me this weekend!
</note>
Copy after login

The error in the first document is that the attribute value is not quoted.
The correct way to write it is: date="12/11/99". The incorrect way to write it: date=12/11/99.

------------- -------------------------------------------------- ------------------

Using XML, whitespace will be preserved
In XML documents, whitespace will not be automatically removed by the parser .

This is different from HTML. In HTML, a sentence like this:

"Hello              my name is Ordm"
Copy after login

will be displayed as:

“Hello my name is Ordm”,
Copy after login

because the HTML parser will automatically remove the blank parts of the sentence.

-------------------------------------------------- ------------------------------------

Using XML, CR / LF are converted Using XML for LF
, new lines are always marked as LF (Line Feed, line feed).

The above is the detailed content of Detailed introduction to the use and learning of xml syntax. For more information, please follow other related articles on the PHP Chinese website!

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

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

Can I open an XML file using PowerPoint? Can I open an XML file using PowerPoint? Feb 19, 2024 pm 09:06 PM

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Convert XML data to CSV format in Python Convert XML data to CSV format in Python Aug 11, 2023 pm 07:41 PM

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

How to handle XML and JSON data formats in C# development How to handle XML and JSON data formats in C# development Oct 09, 2023 pm 06:15 PM

How to handle XML and JSON data formats in C# development requires specific code examples. In modern software development, XML and JSON are two widely used data formats. XML (Extensible Markup Language) is a markup language used to store and transmit data, while JSON (JavaScript Object Notation) is a lightweight data exchange format. In C# development, we often need to process and operate XML and JSON data. This article will focus on how to use C# to process these two data formats, and attach

Using Python to implement data verification in XML Using Python to implement data verification in XML Aug 10, 2023 pm 01:37 PM

Using Python to implement data validation in XML Introduction: In real life, we often deal with a variety of data, among which XML (Extensible Markup Language) is a commonly used data format. XML has good readability and scalability, and is widely used in various fields, such as data exchange, configuration files, etc. When processing XML data, we often need to verify the data to ensure the integrity and correctness of the data. This article will introduce how to use Python to implement data verification in XML and give the corresponding

Convert POJO to XML using Jackson library in Java? Convert POJO to XML using Jackson library in Java? Sep 18, 2023 pm 02:21 PM

Jackson is a Java-based library that is useful for converting Java objects to JSON and JSON to Java objects. JacksonAPI is faster than other APIs, requires less memory area, and is suitable for large objects. We use the writeValueAsString() method of the XmlMapper class to convert the POJO to XML format, and the corresponding POJO instance needs to be passed as a parameter to this method. Syntax publicStringwriteValueAsString(Objectvalue)throwsJsonProcessingExceptionExampleimp

How Python parses XML files How Python parses XML files Aug 09, 2023 am 11:48 AM

How Python parses XML files XML (eXtensibleMarkupLanguage) is a markup language used to represent structured data. When processing XML data, we often need to parse the XML file to extract the required information. Python provides many libraries and modules to parse XML files, such as ElementTree, lxml, etc. This article will introduce how to use Python to parse XML files, with code examples. In Python,

What are the syntax and structure characteristics of lambda expressions? What are the syntax and structure characteristics of lambda expressions? Apr 25, 2024 pm 01:12 PM

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

How to use PHP functions to process XML data? How to use PHP functions to process XML data? May 05, 2024 am 09:15 AM

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

See all articles