I have a list field that stores an XML
string.
I am trying to get the XML
contents and modify a particular tag in the XML
like so:
foreach($item in $list.Items)
{
if($item["XMLField"].Contains("NodeImLookingFor"))
{
$itemNum = $item["ID"]
Write-Host ("{0} - {1}" -f $s, $itemNum)
$a = $item["XMLField"]
$a = $a.Replace("NodeImLookingFor", "ReplacementNode")
$item["XMLField"] = $a
$item.Update()
}
}
The script above, however, deletes the contents in that field. Frustrated, I started over and repopulated the field with the XML
. Once repopulated I tried the following:
foreach($item in $list.Items)
{
if($item["XMLField"].Contains("NodeImLookingFor"))
{
Write-Host $item["XMLField"] #Displays the XML content in the cmd window
$a = $item["XMLField"]
Write-Host $a #Does not display anything
}
}
Now i'm confused should I just run the replace
command straight on $item["XMLField"]
instead of sticking its contents into the $a
variable and editing it from there. My concern is I will delete the list field contents regardless. Please advise.