Simplexml get attributes with a namespace

后端 未结 1 1665
野趣味
野趣味 2020-12-04 02:51

I have an XML Document which has attributes with a namespace. The XML looks like:




        
相关标签:
1条回答
  • 2020-12-04 03:46

    You need to use the namespace when getting the attribute. The android namespace is defined as:

    http://schemas.android.com/apk/res/android

    So you need to pass that to the attributes() method, like this:

    $xml = simplexml_load_string($xmlStr);
    
    echo (string) $xml->application->activity->attributes('http://schemas.android.com/apk/res/android')->name;
    

    Outputs

    com.sunil.tweet.MainActivity

    Codepad Demo

    0 讨论(0)
提交回复
热议问题