24

Using simplexml_load_string() how do I get "ForgotPassword" from the following XML?

<?xml version="1.0" encoding="utf-8"?>
<ForgotPassword>
    <version>1.0</version>
    <authentication>
        <login>username</login>
        <apikey>login</apikey>
    </authentication>
    <parameters>
        <emailAddress>joesmith@example.com</emailAddress>
    </parameters>
</ForgotPassword>
hakre
  • 193,403
  • 52
  • 435
  • 836
John Conde
  • 217,595
  • 99
  • 455
  • 496

1 Answers1

67

Are you wanting to get the name of the root node?

$xml = simplexml_load_string($str);
echo $xml->getName();
Mark
  • 6,254
  • 1
  • 32
  • 31
  • 2
    What about root attributes? E.g. `Artisan Chapter` from ` – caiosm1005 May 21 '14 at 12:54
  • 3
    Just FYI it seems that getName() only became available starting with PHP 5.1.3 - so if you're getting an "undefined method SimpleXMLElement::getName()" error check your PHP version with phpinfo() or php -i on the command line. – Chirael Aug 14 '14 at 21:02