Home >Backend Development >PHP Tutorial >How can I access Node Attributes from a SimpleXML object in PHP?
Accessing Node Attributes from SimpleXML
You're facing an issue accessing attributes from a SimpleXML object. While the var_dump operation reflects the presence of attributes in the XML, the $xml->OFFICE->{'@attributes'} syntax doesn't yield the desired output.
To overcome this, you can leverage the attributes() method:
$attributes = $xml->OFFICE->attributes(); echo $attributes->Token;
This approach retrieves a SimpleXMLElement object containing the attributes. You can then access specific attributes directly, as demonstrated with the Token attribute in the example above.
The above is the detailed content of How can I access Node Attributes from a SimpleXML object in PHP?. For more information, please follow other related articles on the PHP Chinese website!