What are some alternative approaches to selecting elements in XML documents when standard XPath queries do not work in PHP?

When standard XPath queries do not work in PHP for selecting elements in XML documents, an alternative approach is to use SimpleXMLElement and iterate through the elements manually. This allows for more flexibility in selecting elements based on specific criteria or conditions.

$xml = simplexml_load_file('example.xml');

foreach ($xml->children() as $child) {
    if ($child->getName() === 'element_name') {
        // Do something with the element
        echo $child->asXML();
    }
}