Replace text in xml files with Powershell

Hello Everyone

I have number of xml files that I need to edit the value on a specific Attribute , I am trying to do it with powershell but I am struck as the xml structure seems to be bit complex :frowning:

This is the xml file https://pastebin.com/RzeJTUYr

Below is my code . Basically I need to edit the value for the #CdataSection for attribueid called FragmentID .I could able to drill down till the actual data but I am not sure how to update the value here and save it in to a file. Any help would be appreciated. I have a had look at number of forums but could not able to figure out. Any help would be much appreciated. Thanks. :slight_smile:

[xml]$xml = Get-Content C:\xmlcheck\test.xml

($xml.ProjectValues.Values.Value | Where-Object {$_.attributeid -eq "FragmentEntry"})."#cdata-section"

Thanks in advance.

 

 

Try below code

[XML]$XML = Get-Content C:\Scripts\ps.org\powershell.xml
$cData = $XML.ProjectValues.Values.Value | ?{$PSItem.AttributeID -eq 'FragmentEntry'}
$cData.'#cdata-section' = '200' #Accepts only string value
$xml.Save("C:\Scripts\ps.org\powershell.xml")

Thank you Rejikodiyil

It worked :slight_smile: . Cheers.