php|architect's Guide to Web Scraping with PHP - Wind Business ...
php|architect's Guide to Web Scraping with PHP - Wind Business ...
php|architect's Guide to Web Scraping with PHP - Wind Business ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
124 ” XMLReader Extension<br />
false once it reaches the end of the document. As such, it’s perfect for use in a while<br />
loop as shown above.<br />
N o d e s<br />
As in other extensions, each node has a type that is s<strong>to</strong>red in the reader’s<br />
nodeType property. The types in which you are generally interested are still elements<br />
(XMLReader::ELEMENT) and attributes (XMLReader::ATTRIBUTE), possibly also<br />
text (XMLReader::TEXT) and CDATA (XMLReader::CDATA) elements as well. Additionally,<br />
the XMLReader extension has a node type for ending elements (i.e. closing tags),<br />
XMLReader::END_ELEMENT. It s importance will become more obvious in the next section.<br />
The example below shows how <strong>to</strong> check the node type against<br />
an appropriate constant. F o r a list of these constants, see<br />
http://php.net/manual/en/class.xmlreader.php#xmlreader.constants.<br />
localName);<br />
var_dump($doc->value);<br />
var_dump($doc->hasValue);<br />
}<br />
}<br />
?><br />
Also like other extensions, nodes have names. There are two properties for this, name<br />
and localName. The former represents the fully qualified name, including the namespace<br />
specification, while the latter represents the node name by itself and is the one<br />
you will generally want <strong>to</strong> use.<br />
Elements and Attributes<br />
Attribute nodes can have values. When the itera<strong>to</strong>r points <strong>to</strong> an attribute node, the<br />
value property will be populated <strong>with</strong> the node’s value and the hasValue property can<br />
be used <strong>to</strong> check for its presence.