Обновите XML-файл (объект SimpleXMLElement) с помощью строки


У меня есть следующий 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-адрес внутри: имя элемента="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";  

Это не было изменено.

Есть идеи?

Author: AHS, 2014-12-03

1 answers

Попробуйте использовать это:

$result_publisher_Path_2[0] = "http://aaa.com";
 1
Author: jGupta, 2014-12-03 13:21:08