What are some best practices for accessing attribute values using SimpleXMLElement::xpath in PHP?
When using SimpleXMLElement::xpath in PHP to access attribute values, it is important to remember that attribute values are accessed using the '@' symbol followed by the attribute name. This allows you to target specific attributes within the XML data. Additionally, it is recommended to use the xpath function to ensure accurate and efficient querying of the XML data.
$xml = simplexml_load_file('data.xml');
$names = $xml->xpath('//person/@name');
foreach ($names as $name) {
echo $name . "\n";
}