Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # If the id 103 does not exist in the XML file, create it as the key, and the firstName value
- $xmlFile = "c:\temp\students.xml"
- $xml = [xml] (get-content $xmlFile)
- $id = "103"
- $found = ($xml.students.student | Where-Object {$_.id -eq $id})
- if ($found -eq $null) {
- $newStudentXml = $xml.students.AppendChild($xml.CreateElement("student"))
- $newStudentXml.SetAttribute("id",$id)
- $newStudentXml.SetAttribute("firstName","Rebecca")
- }
- $xml.Save($xmlFile);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement