0

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>
3
  • What exactly have you tried? What's the language or tool set is executed in? Commented Jul 7, 2014 at 2:56
  • Sorry forgot to mention where I was doing this. TSQL. What I have tried is :- set @input.modify('replace value of (/ParameterValues/ParameterValue/Name/Value/ text())[1] with "[email protected]"') Commented Jul 7, 2014 at 3:41
  • Please add TSQL to your question tags so experts of that field can help you instead. xP Commented Jul 7, 2014 at 3:44

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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]"')

1 Comment

Thank you. I new it was simple but couldnt see the trees for the forrest.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.