Load Linq Xml assemblies:
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
[System.Reflection.Assembly]::LoadWithPartialName("System.Xml.XPath")
Load your xml (Note, you can use ::Load("file")
instead of ::Parse(...)
to load from file:
$xml = [System.Xml.Linq.XDocument]::Parse("<root> <row>Hey</row> <row>you</row> </root>")
Modify (in this case Remove the first row:
[System.Xml.XPath.Extensions]::XPathSelectElement($xml, "//row").Remove()
Save to file:
$xml.Save("MyXml.xml")
Using System.Xml (instead of System.Xml.Linq):
$doc = new-object "System.Xml.XmlDocument"
$doc.Load("MyXml_int.xml")
$node = $doc.SelectSingleNode("//row");
$node.ParentNode.RemoveChild($node)
$doc.Save("MyXml_out.xml")