Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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# 根目录和第一个子目录上的XDocument命名空间_C#_Xml_Namespaces - Fatal编程技术网

C# 根目录和第一个子目录上的XDocument命名空间

C# 根目录和第一个子目录上的XDocument命名空间,c#,xml,namespaces,C#,Xml,Namespaces,我正在使用XDocument构建一个xml文件 XDocument single = new XDocument( new XDeclaration("1.0", "UTF-8", "true"), new XElement(_namespace + "vcards", XElement.Parse(BuildCardEntry(contact)))); 在BuildCardEntrycon

我正在使用XDocument构建一个xml文件

XDocument single = new XDocument(
                new XDeclaration("1.0", "UTF-8", "true"),
                new XElement(_namespace + "vcards",
                    XElement.Parse(BuildCardEntry(contact))));
在BuildCardEntrycontact中,我也将名称空间添加到每个XElement中。 但是我的代码会这样做

<vcards xmlns="urn:ietf:params:xml:ns:vcard-3.0">
  <vcard xmlns="urn:ietf:params:xml:ns:vcard-3.0">
相反

<vcards xmlns="urn:ietf:params:xml:ns:vcard-3.0">
  <vcard>
有人知道如何解决这个问题吗?

保存xml时使用SaveOptions.ommitDuplicateNamespaces参数

single.Save(..., SaveOptions.OmitDuplicateNamespaces);