Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在使用xml序列化时如何摆脱xmlns_C#_.net - Fatal编程技术网

C# 在使用xml序列化时如何摆脱xmlns

C# 在使用xml序列化时如何摆脱xmlns,c#,.net,C#,.net,我不希望将以下内容附加到根元素 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xmlns:xsd=”http://www.w3.org/2001/XMLSchema“> 使用XML序列化时应该做什么。使用以下方法: 注意最后一个参数(ns)。是的,我在等答案!你能回答这个问题吗 public class Foo { } class Program { static void Main() { var f

我不希望将以下内容附加到根元素

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xmlns:xsd=”http://www.w3.org/2001/XMLSchema“>

使用XML序列化时应该做什么。

使用以下方法:


注意最后一个参数(
ns
)。

是的,我在等答案!你能回答这个问题吗
public class Foo { }

class Program
{
    static void Main()
    {
        var foo = new Foo();
        var serializer = new XmlSerializer(foo.GetType());
        var ns = new XmlSerializerNamespaces();
        ns.Add(string.Empty, string.Empty);
        serializer.Serialize(Console.Out, foo, ns);
    }
}