- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete the specific node from the XML file using PowerShell?
To delete the specific XML node from the PowerShell, we can use the RemoveChild() method of the XML.
For example, We have a sample XML file from Microsoft.
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)
We have saved the above file into C:\Temp\SampleXml.XML and we need to delete the book node with attribute ‘bk102’ and for that, we will use the XPath method of the XML.
Below commands will first search the XML book node with the book attribute ‘bk102’ and then we will delete it.
$xml = [xml](Get-Content C:\Temp\SampleXML.xml) $node = $xml.SelectSingleNode("//book[@id='bk102']") $node.ParentNode.RemoveChild($node) | Out-Null $xml.Save('C:\Temp\SampleXML.xml')
If you want to delete all the nodes which have the name “Book”, we can use the below commands.
$xml = [xml](Get-Content C:\Temp\SampleXML.xml) $xml.SelectNodes("//book") $nodes = $xml.SelectNodes("//book") foreach($node in $nodes){$node.ParentNode.RemoveChild($node)}
In the above example, SelectNodes(‘//book’) method will select all nodes having the name Book and then deletes them.
- Related Articles
- How to update the specific node of the XML file using PowerShell?
- How to add an attribute to the XML file using Powershell?
- How to delete all users from specific OU using PowerShell?
- How to delete all the file contents using PowerShell?
- How to read the XML file in PowerShell?
- How to delete the specific tag of Azure VM using PowerShell?
- How to delete the azure blob (File) using Azure CLI in PowerShell?
- How to delete the local group from the windows system using PowerShell?
- How to Delete Specific Line from a Text File in Python?
- How to delete the Organizational Unit (OU) from the active directory using PowerShell?
- How to get specific nodes in xml file in Python?
- How to exclude specific file names using Get-ChildItem in PowerShell?
- How to delete the windows certificate using PowerShell?
- How to add a new element in the XML using PowerShell?
- How to get the Azure images available from the specific publisher using PowerShell?

Advertisements