Here is an example
$x = [xml]@'
<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>
'@
$newNode = $x.CreateElement('bookSold')
$newNode.InnerText = 1000
$newNode.SetAttribute('usa', 50)
$newNode.SetAttribute('Europe', 50)
[void]$x.DocumentElement.SelectSingleNode('/catalog/book').InsertBefore(
$newNode,
$x.DocumentElement.SelectSingleNode('/catalog/book/genre'))
$document = [System.Xml.XmlDocument]::new()
#PS4 and lower: $document = New-Object -TypeName 'System.Xml.XmlDocument' -ArgumentList @()
$document.Load('S:\SCRIPTS\XMLTest\xmlTest.xml')
$newNode = $document.CreateElement('bookSold')
$newNode.InnerText = 1000
$newNode.SetAttribute('usa', 50)
$newNode.SetAttribute('Europe', 50)
[void]$document.DocumentElement.SelectSingleNode('/catalog/book').InsertBefore(
$newNode,
$document.DocumentElement.SelectSingleNode('/catalog/book/genre'))
$document.Save('S:\SCRIPTS\XMLTest\xmlTest.xml')