Element Countable - ThomasWeinert/FluentDOM GitHub Wiki

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)
⚠️ **GitHub.com Fallback** ⚠️