我有一个 XML 文档,其中包含带有命名空间的属性。 XML 看起来像:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sunil.tweet"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.sunil.tweet.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我怎样才能提取android:name
属性来自于activity
tag?
获取属性时需要使用命名空间。这android
命名空间定义为:
http://schemas.android.com/apk/res/android http://schemas.android.com/apk/res/android
所以你需要将其传递给attributes() https://www.php.net/manual/en/simplexmlelement.attributes.php方法,像这样:
$xml = simplexml_load_string($xmlStr);
echo (string) $xml->application->activity->attributes('http://schemas.android.com/apk/res/android')->name;
Outputs
com.sunil.tweet.MainActivity
键盘演示 http://codepad.org/hpWdfH5S
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)