user3810822
user3810822

Reputation: 1

XML Replace node value

I am trying to update XML node and while it does not generate an error it does not update the value.

the xml

    <ParameterValues>
  <ParameterValue>
    <Name>TO</Name>
    <Value>[email protected]</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>IncludeReport</Name>
    <Value>True</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>RenderFormat</Name>
    <Value>MHTML</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>Subject</Name>
    <Value>@ReportName was executed at @ExecutionTime</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>IncludeLink</Name>
    <Value>True</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>Priority</Name>
    <Value>NORMAL</Value>
  </ParameterValue>
</ParameterValues>

The update string.

  1. (This is what Im tring to change - <Value>[email protected]</Value> )

    set @input.modify('replace value of (/ParameterValues/ParameterValue/Name/Value/ text())[1] with "[email protected]"')

If I change the string to update the Name node it updates with "[email protected]"?

1.<Name>TO</Name>

set @input.modify('replace value of (/ParameterValues/ParameterValue/Name/ text())[1] with "[email protected]"')

Example result

<ParameterValues>
  <ParameterValue>
    <Name>[email protected]</Name>
    <Value>[email protected]</Value>
  </ParameterValue>

Upvotes: 0

Views: 135

Answers (2)

Mikael Eriksson
Mikael Eriksson

Reputation: 138960

You have an extra Name node specified in your update statement.

Try this instead to replace the value of the first ParameterValuenode.

replace value of (/ParameterValues/ParameterValue/Value/text())[1] 
                    with "[email protected]"

If you want to make sure that you only replace the value of the ParameterValue where Name is TO you should use a predicate on the ParameterValue node.

replace value of (/ParameterValues/ParameterValue[Name = "TO"]/Value/text())[1] 
                    with "[email protected]"')

Upvotes: 0

user3689629
user3689629

Reputation: 29

all you want sir is to update... try use this

$doc = new DOMDocument();
$doc->load( xml file name );

$doc->formatOutput = true;
$doc->getElementsByTagName("Value")->item(0)->nodeValue = $TheNewValue; 
$doc->save("pathwheroverwritethefile");

i wish i could help.... i think the array value on item is the error...

Upvotes: 1

Related Questions