Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Below is my xml file
  2. <Co>
  3. <ta>
  4. <description>folder</description>
  5. <tr>
  6. <description>new</description>
  7. <in> #i also want to delete this tag but my code not delete this tag . It just delete the tags between <in> tag
  8. <mId>194</mcInterceptId> #Tag deletion starts here
  9. <description>a</description>
  10. <se>
  11. <seType>921</seType>
  12. </se> #Tag deletion ends here
  13. </in>
  14. <in> ##i also want to delete this tag but my code not delete this tag
  15. <mId>19</mId>
  16. <description>b</description>
  17. <se>
  18. <seType>176</seType>
  19. </se>
  20. </in>
  21. </tr>
  22. </ta>
  23. </Con>
  24. Below is my code
  25.  
  26. $name= Read-Host "enter seType"
  27. $result = Get-ChildItem -Path 'D:ScriptOutput' -Filter 'Export*.xml' -File -Recurse |
  28. ForEach-Object {
  29. $file = $_.FullName
  30.  
  31. [xml]$xml = Get-Content -Path $file
  32. $array = @($xml.Co.ta.tr.in.se | Where-Object { $_.'seType' -eq $name })
  33. if ($array) {
  34.  
  35. [PSCustomObject]@{
  36. 'File' = $file
  37. }
  38.  
  39. $array | ForEach-Object {
  40. $_.ParentNode.RemoveAll()
  41. } 2>&1 | Out-Null
  42.  
  43.  
  44.  
  45.  
  46. Write-Host "Saving file '$file'"
  47. $xml.Save($file)
  48. }
  49. else {
  50. Write-Host "File '$file' did not contain sTypeType $name"
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement