Nodes

As in other extensions, each node has a type that is stored in the reader’s nodeType property. The types in which you are generally interested are still elements (XMLReader::ELEMENT) and attributes (XMLReader::ATTRIBUTE), possibly also text (XMLReader::TEXT) and CDATA (XMLReader::CDATA) elements as well. Additionally, the XMLReader extension has a node type for ending elements (i.e. closing tags), XMLReader::END_ELEMENT. Its importance will become more obvious in the next section.

The example below shows how to check the node type against an appropriate    constant.    For a list of these constants, see http://php.net/manual/en/class.xmlreader.php#xmlreader.constants.

<?php
while ($doc->read()) {
if ($doc->nodeType == XMLReader::ELEMENT) {
var_dump($doc->localName);
var_dump($doc->value);
var_dump($doc->hasValue);
}
}
?>

Also like other extensions, nodes have names. There are two properties for this, name and localName. The former represents the fully qualified name, including the namespace specification, while the latter represents the node name by itself and is the one you will generally want to use.


© XMLReader Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (03.09.2014)
Views: 359 | Rating: 0.0/0
Total comments: 0
avatar