C# .NET - add two namespaces to the xml root attribute ( XML serialization)

Asked By Pranay on 04-May-12 12:03 PM
I have to serialize xml data so I created a class...

XmlRootAttribute

("Customer", Namespace = "http://www.xxx.com/xx/xxx/v2"

, IsNullable = false)]

public class Customer

{


public string TypeOf;

public string Name;

public Address Address;

Everything is good except I have to add two namespaces to Root Attribute "Customer" like this


<?xml version="1.0" encoding="utf-8"?>
<Customer xmlns:ns2="http://www.ixxxx.com/xx/xx/xx" xmlns="http://www.yyy.com/yy/yy/v2">
how do I do it? 


Thanks for your help.
PS
kalpana aparnathi replied to Pranay on 04-May-12 01:52 PM
hi,

Try like this example modify it accordingly:

XmlElement root = doc.CreateElement("EMP");
root
.SetAttribute("xmlns:EMP", "http://www.example.com");
root
.SetAttribute("xmlns:EMP", "http://www.example.com");
doc
.AppendChild(root);


Regards,