我有以下XML文件更新XML文件(SimpleXMLElement對象)使用的字符串
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548">
<hashTree>
<TestPlan ...>
<elementProp name="TestPlan.user_defined_variables" ...>
<collectionProp name="Arguments.arguments">
<elementProp name="nb.publisher_Path" elementType="Argument">
<stringProp name="Argument.name">nb.publisher_Path</stringProp>
<stringProp name="Argument.value">http://mmm.com</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp> ....
,我想裏面更新網址:elementProp名= 「nb.publisher_Path」
來自:http://mmm.com 於:http://aaa.com
,所以我已經寫了下面的PHP代碼:
<?php
$xml = new SimpleXmlElement(file_get_contents("C://...Testing_User.jmx"));
$result_publisher_Path_2 = $xml->xpath('//elementProp[@name="nb.publisher_Path"]/stringProp[@name="Argument.value"]')[0];
$result_advertiser_Path = $xml->xpath('//elementProp[@name="nb.advertiser_Path"]/stringProp[2]');
$result_adbrooker_Path = $xml->xpath('//elementProp[@name="nb.adbrooker_Path"]/stringProp[2]');
echo ($result_publisher_Path_2);
(string)$xml->xpath('//elementProp[@name="nb.publisher_Path"]/stringProp[@name="Argument.value"]')[0] = "http://aaa.com";
echo $xml->asXml();
所以
echo ($result_publisher_Path_2);
的結果是,我想更換正確的網址,當我試圖與
(string)$xml->xpath('//elementProp[@name="nb.publisher_Path"]/stringProp[@name="Argument.value"]')[0] = "http://aaa.com";
改變它,它沒有被改變。
任何想法?
請簡化您的XML減少到最低限度。 – michi 2014-12-03 12:44:15