Skip to content
Thomas Weinert edited this page Jul 29, 2014 · 3 revisions

FluentDOM\Element Countable

FluentDOM\Element implements the Countable interface. It returns the count of child nodes, or in other words $this->childNodes->length. Be aware that this will return whitespace nodes, too.

Example

$xml = <<<'XML'
<items>
  <item></item>
  <item></item>
  <item></item>
</items>
XML;

require_once(__DIR__.'/../../vendor/autoload.php');

$dom = new FluentDOM\Document();
$dom->preserveWhiteSpace = FALSE;
$dom->loadXML($xml);

var_dump(count($dom->documentElement));

Output

int(3)
Clone this wiki locally