I need to add an attribute on root element, but in certain position:
<METATRANSCRIPT xmlns="http://www.mpi.nl/IMDI/Schema/IMDI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Date="2016-01-29" FormatId="IMDI 3.03" Originator="" Type="SESSION"
Version="0"
xsi:schemaLocation="http://www.mpi.nl/IMDI/Schema/IMDI ./IMDI_3.0.xsd"
ArchiveHandle="">
The attribute ArchiveHandle="" needs to stay between xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and Date="2016-01-29".
How can I solve this, and put the attribute in the right place?
This is my code:
Get-ChildItem -Path 'Path\To\XML\Files' -Recurse -Include "*.imdi" -File | ForEach-Object
{
[xml]$xml = Get-Content $_.FullName;
$xml= $xml.METATRANSCRIPT.OuterXml;
$xmlAtt = $xml.CreateAttribute("ArchiveHandle")
$xsi= $xml.DocumentElement.xsi
$xmlAttRef = $xml.DocumentElement.Attributes.Append($xmlAtt)
$xml.Save($_.FullName)
}
Thanks for any help