XML Guide—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 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 (just like saying "this document is a note"):
The 3rd--6th line of the document Describes the four child nodes of the root element (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:
Can you tell from this document that this is the note Ordm left for Lin? Can we not admit that XML is a beautiful self-describing language?
All XML documents must have a closing tag
In XML documents, it is illegal to ignore 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 that the first line in the above example does not have an end 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 different from 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 inclusions 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>
All elements in XML 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>
Attribute values must use quotation marks ""
In XML, the attribute value of an element without quotation marks is 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>
<?xml version="1.0" encoding="ISO-8859-1"?> <note date="12/11/99"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
The error in the first document is that the attribute value is not quoted.
The correct way of writing is: date="12/11/99". The incorrect way of writing: date=12/11/99.
Using XML, whitespace will be preserved
In XML documents , the 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 to LF
Using XML, new lines are always marked as LF (Line Feed, line feed).
Do you know what a typewriter is? Haha, a typewriter is a specialized typing machine used in the last century. ^&^
When you finish typing a line of words on a typewriter, you usually have to move the typehead to the left end of the paper.
In Windows applications, new lines in text are usually identified as CR LF (carriage return, line feed, carriage return, line feed). In Unix applications, new lines are usually identified as LF. There are also applications that only use CR to represent a new line.
Comments in XML
The syntax of comments in XML is basically the same as that in HTML.
There is nothing special about XML
There is really nothing special about XML. It's just plain text held together by angle brackets.
Software that edits ordinary text can also edit XML documents.
However, in an application that supports XML, XML tags often correspond to special operations. Some tags may be visible, while some tags may not be displayed without any special operations.
The above is the XML guide - XML syntax content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

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



When it comes to API development, you may think of DjangoRESTFramework, Flask, and FastAPI. Yes, they can be used to write APIs. However, the framework shared today allows you to convert existing functions into APIs faster. It is Sanic . Introduction to Sanic Sanic[1] is a Python3.7+ web server and web framework designed to improve performance. It allows the use of the async/await syntax added in Python 3.5, which can effectively avoid blocking and improve response speed. Sanic is committed to providing a simple and fast way to create and launch

With the release of PHP 8.0, a new type alias syntax has been added, making it easier to use custom types. In this article, we'll take a closer look at this new syntax and its impact on developers. What is a type alias? In PHP, a type alias is essentially a variable that references the name of another type. This variable can be used like any other type and declared anywhere in the code. The main function of this syntax is to define custom aliases for commonly used types, making the code easier to read and understand.

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.

The connection and difference between Go language and JS Go language (also known as Golang) and JavaScript (JS) are currently popular programming languages. They are related in some aspects and have obvious differences in other aspects. This article will explore the connections and differences between the Go language and JavaScript, and provide specific code examples to help readers better understand these two programming languages. Connection: Both Go language and JavaScript are cross-platform and can run on different operating systems.

PHP is a server-side scripting language widely used in Web development, and PHP8.0 version introduces a new parent class calling syntax to make object-oriented programming more convenient and concise. In PHP, we can create a parent class and one or more subclasses through inheritance. Subclasses can inherit the properties and methods of the parent class, and can modify or extend their functionality by overriding the methods of the parent class. In ordinary PHP inheritance, if we want to call the method of the parent class in the subclass, we need to use the parent keyword to refer to the parent

To master basic CSS selector syntax, specific code examples are required. CSS selectors are a very important part of front-end development. They can be used to select and modify various elements of HTML documents. Mastering basic CSS selector syntax is crucial to writing efficient stylesheets. This article will introduce some common CSS selectors and corresponding code examples. Element selector The element selector is the most basic selector, which can select the corresponding element by its tag name. For example, to select all paragraphs (p elements), you can use

Introduction to the syntax and usage of power operation in C language: In C language, power operation (poweroperation) is a common mathematical operation, which is used to calculate the power of a number. In C language, we can use standard library functions or custom functions to implement exponentiation operations. This article will introduce the syntax and usage of exponentiation operation in C language in detail, and provide specific code examples. 1. Use the pow() function in math.h. In C language, the pow() function is provided in the math.h standard library for executing

The C programming language C is a general-purpose, high-level language originally developed by Dennis M. Ritchie at Bell Labs to develop the UNIX operating system. C was first implemented in 1972 on the DECPDP-11 computer. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, C compiler, and almost all UNIX applications are written in C. For various reasons, C language has now become a widely used professional language. It is a structured language that is easy to learn, it produces efficient programs, it can handle low-level activities, and it can run on a variety of computers.
