03.02.2014 Views

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 ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

XMLReader Extension ” 127<br />

DOM I n t e r o p e r a t i o n<br />

One nice feature of the XMLReader extension is the expand() method, which returns<br />

an object of the equivalent DOM extension class for the node <strong>to</strong> which the itera<strong>to</strong>r<br />

currently points. Element nodes, for example, cause this method <strong>to</strong> return a<br />

DOMElement instance.<br />

The example below illustrates a modification <strong>to</strong> the previous example and provides<br />

another alternative <strong>to</strong> the readString() method for getting at the contents of<br />

table cells by taking advantage of this DOM interoperability.<br />

<br />

Closing Documents<br />

Once all necessary read operations have been conducted on a document, the close()<br />

method of the XMLReader instance should be called <strong>to</strong> cleanly terminate file access or<br />

otherwise indicate that access <strong>to</strong> the original data source is no longer needed.<br />

W r a p - U p<br />

H o p e f u l l y this chapter has given you an idea of how pull parsers work in general<br />

and when it’s better <strong>to</strong> use one like XMLReader o v e r a tree parser. F o r<br />

more information on XMLReader, check out its section in the <strong>PHP</strong> manual at<br />

http://www.php.net/manual/en/book.xmlreader.php.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!