What are some common methods to access data in an XML array using PHP, specifically with the simplexml extension?

When working with XML data in PHP using the simplexml extension, you can access data in an XML array by using methods provided by the SimpleXMLElement class. Some common methods include using the arrow operator (->) to access elements by name, iterating through child elements with foreach loops, and using XPath queries to retrieve specific nodes.

// Load XML data from a file
$xml = simplexml_load_file('data.xml');

// Accessing elements by name
echo $xml->elementName;

// Iterating through child elements
foreach ($xml->children() as $child) {
    echo $child->getName() . ': ' . $child;
}

// Using XPath queries
$nodes = $xml->xpath('//elementName');
foreach ($nodes as $node) {
    echo $node;
}