


XML operation of PHP extension (2) - XML parser installation and overview
1. Overview and installation
XML (eXtensible Markup Language) is a language used on the Internet. A data format for interacting with structured documents. It is a standard defined by the Internet Society (W3C). Information about XML and related technologies can be found at http://www.php.cn/.
This PHP extension implementation supports expat written in PHP by James Clark. This toolkit can parse (but not validate) XML documents. It supports 3 character encodings provided by PHP: US-ASCII, ISO-8859-1 and UTF-8. UTF-16 is not supported.
This extension creates an XML parser and defines handlers for different XML events. Each XML parser also has a handful of parameters that can be adjusted.
This extension requires the libxml PHP extension. This means that --enable-libxml needs to be used, although this will be done implicitly since libxml is enabled by default.
By default, this extension uses expat compat layer. You can also use expat. This library is located at http://www.php.cn/. Using the Makefile in the expat library will not build the library file by default. You can use the following build rules to build:
1 2 3 |
|
--disable-xml
These functions are enabled by default and use the bundled expat library . You can disable XML support through the parameter--disable-xml. If you compile PHP as a module with Apache 1.3.9 or higher, PHP will automatically use the expat library bundled with Apache. If you do not want to use the bundled expat library, please use the parameter --with-expat-dir=DIR when running PHP's configure configuration script, where DIR should point to the root directory of the expat installation.
The Windows version of PHP has built-in support for this extension. No additional extensions need to be loaded to use these functions. 2. Event processorXML event processor is defined as follows: PHP handler functionEvent description##xml_set_element_handler()xml_set_character_data_handler()xml_set_processing_instruction_handler()xml_set_default_handler()xml_set_unparsed_entity_decl_handler()xml_set_notation_decl_handler()##xml_set_external_entity_ref_handler()When This handler is called when the XML parser finds a reference to an external parsed ordinary entity. For example, refer to a file or URL. Examples can be found in the XML external entity routines.3. Capitalization conversion
The element processing function can convert the element name into case-folded (capital letters) form. Case-folding is defined as "a string operation that replaces non-uppercase letters with their corresponding uppercase letters." In other words, in XML, case-folding is converting to uppercase.
By default, all element names passed through the processing function are converted to uppercase letters. Each XML parser can query and control this function through the xml_parser_get_option() and xml_parser_set_option() functions respectively.
4. Error codes
The following constants are XML-related error codes (return values of the xml_parse() function):
-
XML_ERROR_NONE
XML_ERROR_NO_MEMORY
XML_ERROR_SYNTAX
XML_ERROR_NO_ELEMENTS
XML_ERROR_INVALID_TOKEN
XML_ERROR_UNCLOSED_TOKEN
XML_ERROR_PARTIAL_CHAR
XML_ERROR_TAG_MISMATCH
XML_ERROR_DUPLICATE_ATTRIBUTE
- ##XML_ERROR_JUNK_AFTER_DOC_ELEMENT ##XML_ERROR_PARAM_ENTITY_REF
- ##XML_ERROR_RECURSIVE_ENTITY_REF
- XML_ERROR_ASYNC_ENTITY
- XML_ERROR_BAD_CHAR_REF
- #XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF ##XML_ERROR_MISPLACED_XML_PI
- ##XML_ERROR_UNKNOWN_ENCODING
- XML_ERROR_INCORRECT_ENCODING
- XML_ERROR_UNCLOSED_CDATA_SECTION
- XML_ERROR_EXTERNAL_ENTITY_HANDLING
##5. Character encoding
PHP’s XML extension passes through several different The character encoding supports the Unicode character set. There are two types of character encodings, original encoding and target encoding. In PHP's internal presentation, documents are always encoded in UTF-8. When the XML is parsed, the original encoding is completed. When creating an XML parser, you can specify the original encoding (this encoding cannot be modified later in the XML parser's life cycle). The supported raw encodings are ISO-8859-1, US-ASCII and UTF-8. The first two are single-byte encodings, that is, each character is represented as one byte. UTF-8 can encode characters into a series of variable numbers (up to 21) of bits, arranged into 1 to 4 bytes. The default raw encoding used in PHP is ISO-8859-1.
When PHP passes the data to the XML processing function, the target encoding is completed. When creating an XML processor, the target encoding is set to be the same as the original encoding, but can be modified at will. Target encoding affects character data and tag names, as well as processing instruction targets. If the XML parser encounters a character outside the range that the original encoding can represent, it will return an error.
If PHP encounters a character in the parsed XML document that cannot be represented by the specified target encoding, the problem character will be "downgraded". Typically, those characters are replaced with question marks (?).
The above is the XML operation of PHP extension (2) - XML parser installation and overview. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
When XML is parsed When the browser encounters the opening or closing tag, the element event is triggered. Open tags and closing tags have different handlers. | |
The character data range refers to all non-tagged content in the XML document, including spaces between tags. Note that the XML parser does not add or remove any whitespace, it is up to the application (you) to determine whether the whitespace is meaningful. | |
PHP programmers must be proficient in processing instructions (PI). is a processing instruction, where php is called the "processing instruction object". Except for all processing instruction objects starting with "XML" which are reserved by the system, other processing functions are specified by the application program. | |
If other processing functions are not executed, the default processing function will be executed. Information such as XML and document type declarations are available in the default handler functions. | |
Unparsed entity declaration (NDATA) will call this handler function. | |
Symbol declaration will call this handler function | |

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





You can check which extensions are used by PHP by viewing the phpinfo() function output, using command line tools, and checking the PHP configuration file. 1. View the phpinfo() function output, create a simple PHP script, save this script as phpinfo.php, and upload it to your web server. Access this file in the browser and use the browser's search function. Just look for the keyword "extension" or "extension_loaded" on the page to find information about the extension.

MDI files are a common electronic document format, whose full name is Microsoft Document Imaging. It is a file format developed by Microsoft Corporation for storing and displaying scanned documents. MDI files allow users to scan paper documents into digital images that can be viewed, edited, and printed from a computer. MDI files have many advantages, the first being their high compressibility. MDI files can save scanned images in the smallest file size, which is very beneficial for storing and transmitting documents. Secondly

How to use PHP to extend PDO to connect to Oracle database Introduction: PHP is a very popular server-side programming language, and Oracle is a commonly used relational database management system. This article will introduce how to use PHP extension PDO (PHPDataObjects) to connect to Oracle database. 1. Install the PDO_OCI extension. To connect to the Oracle database, you first need to install the PDO_OCI extension. Here are the steps to install the PDO_OCI extension: Make sure

How to use PHP to extend the report generation function of SuiteCRM SuiteCRM is a powerful open source CRM system that provides rich functions to help enterprises manage customer relationships. One of the important functions is report generation. Using reports can help enterprises better understand their business situations and make correct decisions. This article will introduce how to use PHP to extend the report generation function of SuiteCRM and provide relevant code examples. Before starting, you need to make sure that SuiteCRM is installed.

When developing with PHP, we may need to use some PHP extensions. These extensions can provide us with more functions and tools, making our development work more efficient and convenient. But before using these extensions, we need to install them first. This article will introduce you to how to install PHP extensions. 1. What is a PHP extension? PHP extensions refer to components that provide additional functionality and services to the PHP programming language. These components can be installed and used through PHP's extension mechanism. PHP extension can help us with

PHP is a popular server-side scripting language that can handle dynamic content on web pages. The geoip extension for PHP allows you to get information about the user's location in PHP. In this article, we’ll cover how to use PHP’s geoip extension. What is the GeoIP extension for PHP? The geoip extension for PHP is a free, open source extension that allows you to obtain data about IP addresses and location information. This extension can be used with the GeoIP database, a database developed by MaxMin

Pagoda Panel is an open source server management panel. While providing website operators with convenient website management, database management, SSL certificate management and other services, it also provides powerful PHP extension and PHP version management functions, making server management easier. Be more simple and efficient. 1. PHP extension PHP extension is a module used to enhance PHP functions. By installing PHP extensions, more functions and services can be implemented, such as: accelerator: accelerator can significantly improve PHP performance, and reduce service load by caching PHP scripts.

PHP extension development is the art of creating custom functionality, extending PHP core functionality and building more powerful applications. It opens up new possibilities in the PHP world, allowing developers to transcend the basic limitations of the language. This article will take you on a journey of PHP extension development, providing you with comprehensive knowledge and practical guidance from basic concepts to advanced techniques. PHP extension development basics Before starting PHP extension development, you need to understand some basic concepts. What are PHP extensions? A PHP extension is a dynamic link library (DLL) that extends PHP core functionality and provides new data types, functions and classes. Advantages of PHP Extensions PHP extensions have many advantages, including: scalability, flexibility, performance optimization, and code reuse. PHP
