Skip to content
Thomas Weinert edited this page Jul 12, 2018 · 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');

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

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

Output

int(3)
Clone this wiki locally