Delete tag xml

Welcome Forums General PowerShell Q&A Delete tag xml

Viewing 2 reply threads
  • Author
    • #268925
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      I have a big XML file, and it looks like this for example:


      What I want is, if the word “Disk 2” is anywhere beetween <game> to </game> Then I want to remove the whole <game> tag ( frome <game to </game>. There are thousands of different game tags in the xml, so doing it manually would take some time. Tried to find a way to do it in Notepad++, but I could only mark lines that contained the word “Disk 2” and then delete just that line.

      • This topic was modified 1 month ago by mrfomt79.
      • This topic was modified 1 month ago by mrfomt79.
    • #268934
      Topics: 9
      Replies: 170
      Points: 836
      Helping Hand
      Rank: Major Contributor

      Using VI versus notepad, you could do the following:

      To delete all lines containing “game” (remove the /d to show the lines that the command will delete):

    • #269174
      Senior Moderator
      Topics: 9
      Replies: 1422
      Points: 5,289
      Helping Hand
      Rank: Community MVP

      you can do this using XML object methods. you can read the XML file and cast it to [xml] type.

      The use XPath to find the XML element to remove.

      Iterate through the results and remove the node from the parent element.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.