- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 add a new element in the XML using PowerShell?
Suppose we have a XML file as shown below.
<?xml version="1.0"?> <catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> </catalog>
We need to add a new node. So we will first load the XML file and then operate on it as shown below.
The below command will save the XML file to the variable.
$xmlfile = [XML](Get-Content C:\Temp\SampleXML.xml)
The below command will create a new XML element
$newelement = $xmlfile.CreateElement("book")
Once the element is created we need to append it to the specific node. Here we need to append a new element underneath the Catalog.
And the last part is to save the XML file using the below command.
You can check the new book element is created.
- How to add an attribute to the XML file using Powershell?
- How to add the new tag to Azure VM using PowerShell?
- How to read the XML file in PowerShell?
- How to delete the specific node from the XML file using PowerShell?
- How to update the specific node of the XML file using PowerShell?
- How to add a new list element under a <ul> using jQuery?
- How to create a new local group using PowerShell?
- How to create a new Azure resource group using PowerShell?
- How to add multiple values in the Hashtable using PowerShell?
- How to create a new local user in windows using PowerShell?
- How to add a new row in a table using jQuery?
- How to add a new value to each element of list in R?
- How to add the tag of Azure VM using PowerShell?
- How to add the entry in the windows host file using PowerShell?