Given the following XML in a table column:
<UserFields>
<UserField>
<Name>UserName</Name>
<Value>test_user</Value>
</UserField>
<UserField>
<Name>Age</Name>
<Value>24</Value>
</UserField>
<UserField>
<Name>Password</Name>
<Value>test1234!</Value>
</UserField>
<UserField>
<Name>AgentPassword</Name>
<Value>1234Test!</Value>
</UserField>
</UserFields>
I want to query the table and update the XML to replace all <Value>
nodes for any node that contains some form of ‘password’. So in the given example, I would want to replace the <Value>
values of the last two <UserField>
nodes to wind up with:
<UserFields>
<UserField>
<Name>UserName</Name>
<Value>test_user</Value>
</UserField>
<UserField>
<Name>Age</Name>
<Value>24</Value>
</UserField>
<UserField>
<Name>Password</Name>
<Value>********</Value>
</UserField>
<UserField>
<Name>AgentPassword</Name>
<Value>********</Value>
</UserField>
</UserFields>
I was able to come up with this:
SET @MyDoc.modify('
replace value of (//UserField[Name="Password"]/Value/text())[1]
with "********"
');
But it requires a hardcoded value of the Name node — it will find and replace the Value
of the node with Password
value but not the Value
node with value of AgentPassword
. Essentially, I’m trying to say [Name contains "Password"]
instead of =
.