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.

102 ” DOM Extension<br />

ties include firstChild and lastChild. Leaf nodes are nodes that have no children,<br />

which can be checked using the hasChildNodes method of DOMNode.<br />

All nodes in a tree have a single parent node, <strong>with</strong> one exception: the root node<br />

from which all other nodes in the tree stem. If two nodes share the same parent,<br />

they are appropriately referred <strong>to</strong> as sibling nodes. This relationship is shown in the<br />

previousSibling and nextSibling properties in DOMNode.<br />

Lastly, child nodes of a node, child nodes of those child nodes, and so on are collectively<br />

known as descendant nodes. Likewise, the parent node of a node, that parent<br />

node’s parent node, and so on are collectively known as ances<strong>to</strong>r nodes.<br />

An example may help <strong>to</strong> showcase this terminology.<br />

<br />

<br />

<br />

Foo<br />

Bar<br />

<br />

<br />

<br />

• html is the root node.<br />

• body is the first (and only) child of html.<br />

• ul is the first (and only) child of body.<br />

• The li nodes containing Foo and Bar are the first and last child nodes of ul<br />

respectively.<br />

• The li node containing Bar node is the next sibling of the li node containing<br />

Foo.<br />

• The li node containing Foo is likewise the previous sibling of the li node containing<br />

Bar.<br />

• The ul and li nodes are descendants of the body node.

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

Saved successfully!

Ooh no, something went wrong!