【发布时间】:2014-12-03 11:48:21
【问题描述】:
我有以下 XML 文件
<?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> ....
我想更新里面的 URL:elementProp name="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);
是我要替换的正确 URL,当我尝试用
更改它时(string)$xml->xpath('//elementProp[@name="nb.publisher_Path"]/stringProp[@name="Argument.value"]')[0] = "http://aaa.com";
它没有改变。
有什么想法吗?
【问题讨论】:
-
请将您的 XML 简化到最低限度。
标签: php xml xpath xml-parsing jmeter