C# XML空白命名空间

C# XML空白命名空间,c#,xml,serialization,namespaces,C#,Xml,Serialization,Namespaces,我正在用以下标题将一个对象序列化为XML <agr:ABWInvoice xmlns:agr="http://services.agresso.com/schema/ABWInvoice/2011/11/14" xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/1

我正在用以下标题将一个对象序列化为XML

<agr:ABWInvoice 
    xmlns:agr="http://services.agresso.com/schema/ABWInvoice/2011/11/14"
    xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd" 
    xmlns:agrlib="http://services.agresso.com/schema/ABWSchemaLib/2011/11/14" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 >
我也尝试了以下内容,但没有给出所需的输出:

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("agrlib", "http://services.agresso.com/schema/ABWSchemaLib/2006/11/20");
ns.Add("", "http://services.agresso.com/schema/ABWInvoice/2006/11/20");
更新:@Vladimir Frolov引导我使用以下方法解决问题:

[Serializable]
[XmlRootAttribute(Namespace = "http://services.agresso.com/schema/ABWInvoice/2006/11/20", IsNullable = true)]
public class ABWInvoice2006
{
...
}

尝试在XmlSerializer构造函数中指定XmlRootAttribute。
下面是一个。

尝试在XmlSerializer构造函数中指定XmlRootAttribute。 这是一个例子

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("agrlib", "http://services.agresso.com/schema/ABWSchemaLib/2006/11/20");
ns.Add("", "http://services.agresso.com/schema/ABWInvoice/2006/11/20");
[Serializable]
[XmlRootAttribute(Namespace = "http://services.agresso.com/schema/ABWInvoice/2006/11/20", IsNullable = true)]
public class ABWInvoice2006
{
...
}