C# 根目录和第一个子目录上的XDocument命名空间
我正在使用XDocument构建一个xml文件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 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);