How can I remove a specific node based on its keyvalue?

Kriti

The task is to remove a node based on either key or value, for e.g the whole entry with key "org.quartz.B" and value="BBB" should be removed.

<config>
 <module>
   <section name="java">
    <entry key="org.quartz.A" value="AAA" />
    <entry key="org.quartz.B" value="BBB" />
    <entry key="org.quartz.C" value="CCC" />
    <entry key="org.quartz.D" value="false" />
   </section>
    <section name="db">
    <entry key="oracle" value="12" />
    <entry key="mssql" value="2012" />
    <entry key="mysql" value="6.1" />       
   </section>
 </module>
</config>

Code which i have tried is

$getxmlpath="C:\test.xml"
$xml=[xml](Get-Content $getxmlpath)
Write-Host ($xml)
$javasection = $xml.config.module | where-Object {$_.name -eq 'java'}
Write-Host ($javasection)
####### dont know how to delete particular node#######
$xml.Save($getxmlpath)
dugas

You can use the RemoveChild method of the XmlNode class:

$childToRemove = $javaSection.entry | ? { $_.Key -eq 'org.quartz.B' }
$javaSection.RemoveChild($childToRemove)

Note that using this to find the element to delete is inefficient as it has to filter through ALL of the elements with the Where-Object cmdlet. If your xml is going to be large, you might want to look at using XPath expressions with a method like: SelectSingleNode.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I use a batch script to remove folder and all of its contents based on folder name in YYYYMMDD format?

From Dev

How can I select a specific XML node and fetch the values in its child nodes

From Dev

How can I remove members of a list of strings of equal length, based on the presence of specific characters in certain positions of the strings?

From Dev

How do I select a node based on one of its edges in igraph?

From Dev

How can i remove a div and its contents from the DOM

From Dev

How can I remove the item and its key from localStorage?

From Dev

How can I remove the item and its key from localStorage?

From Dev

How can I remove symlinks within a folder and its subfolder?

From Dev

How can I tag text based on its indentation?

From Dev

How can I get the extension(s) of a file based on its content?

From Dev

how i can select then hide <a> link based on its text

From Dev

How can I delete the "sheet" node keeping its content intact?

From Dev

How can I delete the "sheet" node keeping its content intact?

From Dev

How can I remove all whitespace from a string except when part of said string is surrounded by a specific character in Node?

From Java

How can I remove specific rules from iptables?

From Java

How can I remove a specific item from an array?

From Dev

How can I remove a specific format from string with RegEx?

From Dev

Python. How can I remove a specific key in an array?

From Dev

How can I select or remove specific element from vector in r?

From Dev

How can I remove specific element from a list?

From Dev

How can i filter/remove a line that a specific word is not exist in the line?

From Dev

Python. How can I remove a specific key in an array?

From Dev

How can I use regex to remove a very specific portion of a string:

From Dev

How can I remove files based on the time they were created?

From Dev

How can I remove objects from array based on multiple conditions?

From Dev

How can I remove files based on the time they were created?

From Dev

How can I remove values array based on array other

From Dev

How can I make it so I can run a specific program, just by typing its name in the console?

From Dev

How can I dynamically select and expand a certain search node depending on its score and the score of its children?

Related Related

  1. 1

    How can I use a batch script to remove folder and all of its contents based on folder name in YYYYMMDD format?

  2. 2

    How can I select a specific XML node and fetch the values in its child nodes

  3. 3

    How can I remove members of a list of strings of equal length, based on the presence of specific characters in certain positions of the strings?

  4. 4

    How do I select a node based on one of its edges in igraph?

  5. 5

    How can i remove a div and its contents from the DOM

  6. 6

    How can I remove the item and its key from localStorage?

  7. 7

    How can I remove the item and its key from localStorage?

  8. 8

    How can I remove symlinks within a folder and its subfolder?

  9. 9

    How can I tag text based on its indentation?

  10. 10

    How can I get the extension(s) of a file based on its content?

  11. 11

    how i can select then hide <a> link based on its text

  12. 12

    How can I delete the "sheet" node keeping its content intact?

  13. 13

    How can I delete the "sheet" node keeping its content intact?

  14. 14

    How can I remove all whitespace from a string except when part of said string is surrounded by a specific character in Node?

  15. 15

    How can I remove specific rules from iptables?

  16. 16

    How can I remove a specific item from an array?

  17. 17

    How can I remove a specific format from string with RegEx?

  18. 18

    Python. How can I remove a specific key in an array?

  19. 19

    How can I select or remove specific element from vector in r?

  20. 20

    How can I remove specific element from a list?

  21. 21

    How can i filter/remove a line that a specific word is not exist in the line?

  22. 22

    Python. How can I remove a specific key in an array?

  23. 23

    How can I use regex to remove a very specific portion of a string:

  24. 24

    How can I remove files based on the time they were created?

  25. 25

    How can I remove objects from array based on multiple conditions?

  26. 26

    How can I remove files based on the time they were created?

  27. 27

    How can I remove values array based on array other

  28. 28

    How can I make it so I can run a specific program, just by typing its name in the console?

  29. 29

    How can I dynamically select and expand a certain search node depending on its score and the score of its children?

HotTag

Archive