What are some alternative methods for debugging XML objects in PHP besides using print_r or var_dump?

When debugging XML objects in PHP, using print_r or var_dump can be cumbersome and difficult to read. An alternative method is to use the DOMDocument class in PHP, which provides a more structured way to access and manipulate XML data. By loading the XML string into a DOMDocument object, you can easily navigate through the XML structure and extract the information you need for debugging purposes.

$xmlString = '<root><element>value</element></root>';

$dom = new DOMDocument();
$dom->loadXML($xmlString);

// Access and debug XML elements
$elements = $dom->getElementsByTagName('element');
foreach ($elements as $element) {
    echo $element->nodeName . ': ' . $element->nodeValue . "\n";
}