


Detailed introduction to the use and learning of xml syntax
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't forget me this weekend!</body> </note>
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>
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't forget me this weekend!</body>
The last line of the document is the end of the root element:
</note>
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
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>
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
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> //正确的
--------------------------------------------- ----------------------------------------
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>
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>
------------------------------------------------ --------------------------------------------------
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>
-------- -------------------------------------------------- -----------------------
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't forget me this weekend!</body> </note>
Tove Jani Reminder Don't forget me this weekend! </note>
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"
will be displayed as:
“Hello my name is Ordm”,
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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 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,

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.

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.
