Explain spaces in xml
For html files, spaces are not important; however, for xml, the default position is to retain space nodes (see below for an explanation of space nodes).
According to the XML specification, the so-called space is any combination sequence of four characters:
------------------ -----
space character (space), the corresponding character value is #x20
return character (Carriage Return), the corresponding character value is #xD
newline character (Newline), the corresponding character value is #xA
Tab character (Tab), the corresponding character value is #x9.
The spaces in the xml file will also form nodes, which are space nodes. Space nodes belong to the text node type.
For XML and ##1. To determine which spaces in the xml input file are important, the xslt processor needs to see these space nodes. The key to the decision is the xml:space attribute.
2. Determine which spaces in the xsl template file are important, the xslt processor should copy it to the result tree, and the key to the decision is the two commands xsl:strip-space
and xsl:preserve-space.
------------------------
If someone The content of a component can only contain components, so the space nodes in the component are insignificant;
If the content of a component is of type #PCDATA, the space nodes within it should be considered important. (Significant).
As for the situation where the component content mixes text content and components, it is impossible to judge. It should depend on the semantic meaning of the component and its content.
-------------------- ---
(1) The xml:space attribute can change the mode of processing space nodes by subsequent XML applications. For example, the xslt processor will be affected by the xml:space attribute.
(2) The end symbols at the end of any column mark or content in the xml file will be replaced by a single new line character (#xA).
(3) Before the attribute value is handed over to the XML application, the XML parser should also perform standardized operations on the attribute value. This is because different operating systems have different combinations of the ending characters of each line of text. For example, the Windows system will end with the return character and the new line character, while the Unix system will only end with the new line character group
symbol. After the XML parser reads the XML file, it first replaces all the ending symbols with a single new line character. This not only unifies the differences in the design of different ending symbols between different systems, but also simplifies the operation difficulty of subsequent XML applications. Such a process is called "normalization".
a. The end character of each text column must be normalized to a single newline character (#xA).
b, any space character (#x20, #xD, #xA, #x9) should be replaced by a space character (#x20).
c, if the attribute value contains a word parameter code, it should be replaced with the reference character, for example,
Will be replaced with newline characters (#xA).
d. If the attribute value contains an entity reference, it should be replaced by its replacement text.
e, any characters other than this should be placed directly into the normalized attribute value.
f. Finally, if the attribute type is not CDATA, the XML parser should further delete the sequence of space characters before and after the attribute value, and if there is a sequence of spaces in the middle of the attribute value, it should also be replaced with a single space character.
After the xslt processor builds the structure tree of the xml input file and xsl template file, it will merge the adjacent text nodes in the component into a single text node, and then merge some Remove text nodes. However, if the text node meets one of the following conditions, it will be retained:
-----------------------
(1) The parent component of the text node is a member of the Set Of Whitespace-preserving Element Names.
(2) There is at least one non-space character in the text node.
(3) There is an xml:space attribute in an ancestor component of the text node, and its value is preserve, and there is no other xml:space attribute value in the recent ancestor component that is default. Other text nodes will be removed.
The above is the detailed content of Explain spaces in xml. 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

Implementing filtering and sorting of XML data using Python Introduction: XML is a commonly used data exchange format that stores data in the form of tags and attributes. When processing XML data, we often need to filter and sort the data. Python provides many useful tools and libraries to process XML data. This article will introduce how to use Python to filter and sort XML data. Reading the XML file Before we begin, we need to read the XML file. Python has many XML processing libraries,

Python implements conversion between XML and JSON Introduction: In the daily development process, we often need to convert data between different formats. XML and JSON are common data exchange formats. In Python, we can use various libraries to convert between XML and JSON. This article will introduce several commonly used methods, with code examples. 1. To convert XML to JSON in Python, we can use the xml.etree.ElementTree module

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

The difference between full-width spaces and half-width spaces. When we use word processing software or edit text content, we sometimes encounter the concept of spaces. Space is a very basic element in typesetting and formatting text, but many people may not know the difference between full-width spaces and half-width spaces. In daily use, we may feel that full-width spaces and half-width spaces have different effects in different situations, but we may not be aware of the subtle differences. First of all, the difference between full-width spaces and half-width spaces is the width they occupy.

Python parses special characters and escape sequences in XML XML (eXtensibleMarkupLanguage) is a commonly used data exchange format used to transfer and store data between different systems. When processing XML files, you often encounter situations that contain special characters and escape sequences, which may cause parsing errors or misinterpretation of the data. Therefore, when parsing XML files using Python, we need to understand how to handle these special characters and escape sequences. 1. Special characters and

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
