略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: xml_parser_create_ns

2024-04-23

xml_parser_create_ns

(PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8)

xml_parser_create_ns 生成一个支持命名空间的 XML 解析器

描述

xml_parser_create_ns(string $encoding = ?, string $sep = ?): resource

函数 xml_parser_create_ns() 建立一个新的支持 XML 命名空间的解析器并返回可被其它 XML 函数使用的资源句柄。

通过有命名空间支持的解析器,传递给各种各样句柄函数的标签参数将由命名空间和标签名组成。命名空间和标签名的分隔符由 seperator 参数制定的字符串决定,其默认值为“:”。

可选参数 encoding 在 PHP 4 中用来指定要被解析的 XML 输入的字符编码方式。PHP 5 开始,自动侦测输入的 XML 的编码,因此 encoding 参数仅用来指定解析后输出数据的编码。在 PHP 4 总,默认输出的编码与输入数据的编码是相同的。如果传递了空字符串,解析器会尝试搜索头 3 或 4 个字节以确定文档的编码。在 PHP 5.0.0 和 5.0.1 总,默认输出的字符编码是 ISO-8859-1,而 PHP 5.0.2 及以上版本是 UTF-8。解析器支持的编码有 ISO-8859-1, UTF-8US-ASCII

请参阅函数 xml_parser_create()xml_parser_free()

add a noteadd a note

User Contributed Notes 2 notes

up
2
jonnyNO at SPAM dot sanriowasteland dot net
20 years ago
This is from the Expat Function Reference by Clark Cooper, which is a reference to the C api.  

"XML_Parser XML_ParserCreateNS(const XML_Char*encoding, XML_Char sep)
Constructs a new parser that has namespace processing in effect. Namespace expanded element names and attribute names are returned as a concatenation of the namespace URI, sep, and the local part of the name. This means that you should pick a character for sep that can't be part of a legal URI."

(from http://www.xml.com/pub/a/1999/09/expat/reference.html)

So thats what this function is for.  Now you know.
up
0
bishop at php dot net
3 years ago
Internals has proposed[1] changing this extension from resource-based to object-based. When this change is made, xml_parser_create_ns will return an object, not a resource. Application developers are encouraged to replace any checks for explicit success, like:

<?php
$res
= xml_parser_create_ns(/*...*/);
if (!
is_resource($res)) {
   
// ...
}
?>

With a check for explicit failure:
<?php
$res
= xml_parser_create_ns(/*...*/);
if (
false === $res) {
   
// ...
}

[
1]: https://marc.info/?l=php-internals&m=154998365013373&w=2

官方地址:https://www.php.net/manual/en/function.xml-parser-create-ns.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3