Powershell - Create an XML with specific namespace

Viewed 1732

I need to create this XML:

<?xml version="1.0" encoding="UTF-8"?>
<SRP xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sample.xsd">

..but while I know how to write the namespace using XMLWriter (eg:

$XmlWriter.WriteAttributeString("xmlns", "xsi", 
"http://www.w3.org/2000/xmlns/", 
"http://www.w3.org/2001/XMLSchema-instance");

..I've been unable to do so in a variable:

[xml]$XML = New-Object System.Xml.XmlDocument
$Declaration=$XML.CreateXmlDeclaration("1.0","UTF-8",$Null)
$XML.AppendChild($Declaration) 

I've tried various combinations of Namespacemanager but to no avail.. it seems a stupid question, but so far I've been unable to replicate it (short of using an here-string with the hardcoded XML and casting it as an XML of course, but I'd prefer to do it the 'proper' way :)

Thanks to everyone reading so far :)

1 Answers
Related