From the PHP manual for count():
Returns the number of elements in var. If var is not an array or an object with implemented Countable interface, 1 will be returned.
DOMNode::$childNodes is a DOMNodeList object. It is not Countable. It will always return one (even if empty). Use its length property instead:
$count = $element->childNodes->length;
Update: DOMNodeList
has been made Countable
from PHP 7.2 onwards.