views:

423

answers:

1

I am serializing an object to xml and would like to set an xmlns attribute to the root node.

eg:

...
<root xmlns="[specified url]">
...
</root>

I cant seem to have an xmlns property/attribute on the member or seem to add the namespace when serializing without a prefix?

Any ideas?

+3  A: 

This can do it as following. For top level use XmlRoot and for Properties use XmlElement

[System.Xml.Serialization.XmlRoot(Namespace="http://topLevelNS")]
class MyClass
{
    [System.Xml.Serialization.XmlElement(Namespace = "http://SomeOtherNS")]
    public int MyVar { get; set; }
}
affan
Thanks, this does add the namespace references but not in the way I need to support the XML format I am trying to duplicate.
Mark Redman