dqn8235 2014-12-03 11:48
浏览 51
已采纳

使用string更新XML文件(SimpleXmlElement Object)

I have the following XML file

<?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> .... 

And i want to update the URL inside: elementProp name="nb.publisher_Path"

from:http://mmm.com to : http://aaa.com

so i have wrote the following PHP code:

<?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();

so the result for

echo ($result_publisher_Path_2);

is the right URL which i want to replace, and when i tried to change it with

(string)$xml->xpath('//elementProp[@name="nb.publisher_Path"]/stringProp[@name="Argument.value"]')[0] = "http://aaa.com";  

it hasn't been changed.

Any Ideas?

  • 写回答

1条回答 默认 最新

  • donglikuang8145 2014-12-03 12:36
    关注

    Try Using this:

    $result_publisher_Path_2[0] = "http://aaa.com";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程