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.
The XMLReader extension is available in PECL for PHP 5.0 and is included in PHP 5.1 by default. It and can be enabled by adding the argument --with--xmlreader to your configure line. The libxml extension is required.
XMLReader->close() - Close the XMLReader input
XMLReader->expand() - Export current node to a DOM node
XMLReader->getAttribute() - Get value of attribute by name
XMLReader->getAttributeNo() - Get value of attribute by position
XMLReader->getAttributeNS() - Get value of attribute by name and URI
XMLReader->getParserProperty() - Indicates if parser property is set or not
XMLReader->isValid() - Indicates if document is valid
XMLReader->lookupNamespace() - Get URI for prefix in scope of node
XMLReader->moveToAttribute() - Positions reader on named attribute
XMLReader->moveToAttributeNo() - Positions reader on attribute by index
XMLReader->moveToAttributeNs() - Position reader on attribute by name and URI
XMLReader->moveToElement() - Move to parent element of current attribute node
XMLReader->moveToFirstAttribute() - Move to first attribute of node
XMLReader->moveToNextAttribute() - Move to next attribute of node
XMLReader->next() - Move to next element skipping children
XMLReader->open() - Set URI to be parsed
XMLReader->read() - Move to next node in stream
XMLReader->setParserProperty() - Set parser property
XMLReader->setRelaxNGSchema() - Set URI of RelaxNG schema to validate against
XMLReader->setRelaxNGSchemaSource() - Set string containing RelaxNG schema to validate against
XMLReader->XML() - Set string of data to be parsed
Таблица 1.
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 был собран с поддержкой этого расширения или же в том случае, если данное расширение подгружается во время выполнения.
Таблица 2. 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 |
Таблица 3. 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 | Subsitute entities and expand references |
Пред. | Начало | След. |
xmlrpc_set_type | Уровень выше | XMLReader->close() |