使用simplexml更改以名称空间为前缀的属性值

时间:2012-10-31 18:46:49

标签: php simplexml

我想使用simplexml:

更改以名称空间为前缀的属性的值
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16">

这些方法不起作用:

$usesSDKTag['android:minSdkVersion'] = $minSdkVersion;
$usesSDKTag['minSdkVersion'] = $minSdkVersion;

1 个答案:

答案 0 :(得分:0)

我最终重新创建节点并添加带名称空间前缀的属性:

if( isset($xmlManifest->{"uses-sdk"}) ) {
     unset($xmlManifest->{"uses-sdk"});
}
$usesSDKTag = $xmlManifest->addChild('uses-sdk');
$usesSDKTag->addAttribute('android:minSdkVersion', $minSdkVersion, 'http://schemas.android.com/apk/res/android');
$usesSDKTag->addAttribute('android:targetSdkVersion', $minSdkVersion, 'http://schemas.android.com/apk/res/android');
$usesSDKTag->addAttribute('android:maxSdkVersion', $maxSdkVersion, 'http://schemas.android.com/apk/res/android');