I have a XMLDocument which, when I save to file, repeats a namespace on most of the elements, as in
<Test>
<Test xmlns="http://example.com/schema1">
<Name xmlns="http://example.com/schema2">xyz</Name>
<AddressInfo xmlns="http://example.com/schema2">
<Address>address</Address>
<ZipCode>zzzz</ZipCode>
</AddressInfo>
...
Is it possible to amend this file so that it uses a namespace prefix throughout the document, ie something like
<Test xmlns="http://example.com/schema1" xmlns:p="http://example.com/schema2" >
<p:Name>xyz</p:Name>
<p:AddressInfo">
<p:Address>address</p:Address>
<p:ZipCode>zzzz</p:ZipCode>
</p:AddressInfo>
...
I have tried adding
doc.DocumentElement.SetAttribute("xmlns:p", "http://example.com/schema2");
but whilst this adds the namespace to the header, the main body of the file is unchanged.
You can simply change
XmlElement.Prefix
property value :