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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探