函数参考
PHP Manual

XMLReader functions

简介

The XMLReader extension is an XML Pull parser. The reader acts as a cursor going forward on the document stream and stopping at each node on the way.

Encoding

It is important to note that internally, libxml uses the UTF-8 encoding and as such, the encoding of the retrieved contents will always be in UTF-8 encoding.

安装

The XMLReader extension is available in PECL as of PHP 5.0.0 and is included and enabled as of PHP 5.1.0 by default. It can be enabled by adding the argument --enable-xmlreader (or --with-xmlreader before 5.1.0) to your configure line. The libxml extension is required.

预定义类

XMLReader

方法

属性

Name Type Read-only Description
attributeCount int yes The number of attributes on the node
baseURI string yes The base URI of the node
depth int yes Depth of the node in the tree starting at 0
hasAttributes bool yes Indicates if node has attributes
hasValue bool yes Indicates if node has a text value
isDefault bool yes Indicates if attribute is defaulted from DTD
isEmptyElement bool yes Indicates if node is an empty element tag
localName string yes The local name of the node
name string yes The qualified name of the node
namespaceURI string yes The URI of the namespace associated with the node
nodeType int yes The node type for the node
prefix string yes The prefix of the namespace associated with the node
value string yes The text value of the node
xmlLang string yes The xml:lang scope which the node resides

预定义常量

以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。

Warning

XMLReader uses class constants since PHP 5.1. Prior releases use global constants in the form XMLREADER_ELEMENT.

XMLReader Node Types
Constant Value Description
XMLReader::NONE (integer) 0 No node type
XMLReader::ELEMENT (integer) 1 Start element
XMLReader::ATTRIBUTE (integer) 2 Attribute node
XMLReader::TEXT (integer) 3 Text node
XMLReader::CDATA (integer) 4 CDATA node
XMLReader::ENTITY_REF (integer) 5 Entity Reference node
XMLReader::ENTITY (integer) 6 Entity Declaration node
XMLReader::PI (integer) 7 Processing Instruction node
XMLReader::COMMENT (integer) 8 Comment node
XMLReader::DOC (integer) 9 Document node
XMLReader::DOC_TYPE (integer) 10 Document Type node
XMLReader::DOC_FRAGMENT (integer) 11 Document Fragment node
XMLReader::NOTATION (integer) 12 Notation node
XMLReader::WHITESPACE (integer) 13 Whitespace node
XMLReader::SIGNIFICANT_WHITESPACE (integer) 14 Significant Whitespace node
XMLReader::END_ELEMENT (integer) 15 End Element
XMLReader::END_ENTITY (integer) 16 End Entity
XMLReader::XML_DECLARATION (integer) 17 XML Declaration node
XMLReader Parser Options
Constant Value Description
XMLReader::LOADDTD (integer) 1 Load DTD but do not validate
XMLReader::DEFAULTATTRS (integer) 2 Load DTD and default attributes but do not validate
XMLReader::VALIDATE (integer) 3 Load DTD and validate while parsing
XMLReader::SUBST_ENTITIES (integer) 4 Substitute entities and expand references

Table of Contents


函数参考
PHP Manual