echo "Found " . count($result) . " nodes with classes starting with 'subtitle':\n";
foreach ($result as $node) {
@ -166,6 +166,8 @@ Converts a node to a string.
### MensBeam\HTML\DOM\Node ###
Common namespace constants are provided in `MensBeam\HTML\DOM\Node` to make using namespaces using the library not so onerous. In addition, constants are provided here to be used with `MensBeam\HTML\DOM\ParentNode::walk`. `MensBeam\HTML\DOM\Node` also implements `\Stringable` which means that any node can be simply converted to a string to serialize it.
```php
namespace MensBeam\HTML\DOM;
@ -210,6 +212,45 @@ Applies the callback filter while walking down the DOM tree and yields nodes mat
- `Node::WALK_STOP`: Stop the walker.
* `includeReferenceNode`: Include `$this` when walking down the tree.
@ -227,13 +268,38 @@ Register PHP functions as XPath functions. Works like `\DOMXPath::registerPhpFun
* `document`: The document to register the functions on.
* `restrict`: Use this parameter to only allow certain functions to be called from XPath. This parameter can be either a string (a function name), an array of function names, or null to allow everything.
##### Example #####
```php
use MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html><body><h1>Ook</h1><pclass="subtitle1">Eek?</p><pclass="subtitle2">Ook?</p></body></html>');
echo "Found " . count($result) . " nodes with classes starting with 'subtitle':\n";
foreach ($result as $node) {
echo "$node\n";
}
```
Output:
```
Found 2 nodes with classes starting with 'subtitle':
<pclass="subtitle1">Eek?</p>
<pclass="subtitle2">Ook?</p>
```
### MensBeam\HTML\DOM\XPathResult ###
`MensBeam\HTML\DOM\XPathResult` implements `\ArrayAccess`, `\Countable`, and `\Iterator` and will allow for accessing as if it is an array when the result type is `MensBeam\HTML\DOM\XPathResult::ORDERED_NODE_ITERATOR_TYPE`, `MensBeam\HTML\DOM\XPathResult::UNORDERED_NODE_ITERATOR_TYPE`, `MensBeam\HTML\DOM\XPathResult::ORDERED_NODE_SNAPSHOT_TYPE`, or `MensBeam\HTML\DOM\XPathResult::UNORDERED_NODE_SNAPSHOT_TYPE`.
`MensBeam\HTML\DOM\XPathResult` implements `\ArrayAccess`, `\Countable`, and `\Iterator` and will allow for accessing as if it is an array when the result type is `MensBeam\HTML\DOM\XPathResult::ORDERED_NODE_ITERATOR_TYPE`, `MensBeam\HTML\DOM\XPathResult::UNORDERED_NODE_ITERATOR_TYPE`, `MensBeam\HTML\DOM\XPathResult::ORDERED_NODE_SNAPSHOT_TYPE`, or `MensBeam\HTML\DOM\XPathResult::UNORDERED_NODE_SNAPSHOT_TYPE`. This is not in the specification, but not being able to simply iterate over a result is absurd.
```php
partial class XPathResult implements \ArrayAccess, \Countable, \Iterator {
}
partial class XPathResult implements \ArrayAccess, \Countable, \Iterator {}
```
## Limitations & Differences from Specification ##