Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Below is my xml file
- <Co>
- <ta>
- <description>folder</description>
- <tr>
- <description>new</description>
- <in> #i also want to delete this tag but my code not delete this tag . It just delete the tags between <in> tag
- <mId>194</mcInterceptId> #Tag deletion starts here
- <description>a</description>
- <se>
- <seType>921</seType>
- </se> #Tag deletion ends here
- </in>
- <in> ##i also want to delete this tag but my code not delete this tag
- <mId>19</mId>
- <description>b</description>
- <se>
- <seType>176</seType>
- </se>
- </in>
- </tr>
- </ta>
- </Con>
- Below is my code
- $name= Read-Host "enter seType"
- $result = Get-ChildItem -Path 'D:ScriptOutput' -Filter 'Export*.xml' -File -Recurse |
- ForEach-Object {
- $file = $_.FullName
- [xml]$xml = Get-Content -Path $file
- $array = @($xml.Co.ta.tr.in.se | Where-Object { $_.'seType' -eq $name })
- if ($array) {
- [PSCustomObject]@{
- 'File' = $file
- }
- $array | ForEach-Object {
- $_.ParentNode.RemoveAll()
- } 2>&1 | Out-Null
- Write-Host "Saving file '$file'"
- $xml.Save($file)
- }
- else {
- Write-Host "File '$file' did not contain sTypeType $name"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement