Is there a more reliable method than empty() for checking if a field is empty in PHP when using XMLReader?

When using XMLReader in PHP, the empty() function may not always accurately determine if a field is empty due to the way XMLReader handles empty elements. A more reliable method is to check if the nodeType is XMLReader::ELEMENT and if the node is empty using the isEmptyElement attribute.

$reader = new XMLReader();
$reader->open('example.xml');

while ($reader->read()) {
    if ($reader->nodeType == XMLReader::ELEMENT && $reader->isEmptyElement) {
        echo "Empty element found: " . $reader->name . "\n";
    }
}

$reader->close();