我使用下面的代码将一个XDocument元素的节点复制到另一个新的XDocument:
#region Namespace...
XNamespace xsd = "http://www.w3.org/2001/XMLSchema";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace schemaLocation = XNamespace.Get("tv:noNamespaceSchemaLocation");
#endregion Namespace...
var doc = new XDocument();
doc.Add(new XElement("tv",
new XAttribute(XNamespace.Xmlns + "xsd", xsd),
new XAttribute(XNamespace.Xmlns + "xsi", xsi),
new XAttribute(xsi + "schemaLocation", schemaLocation))
);
doc.Root.Add(new XElement("channel",
new XAttribute("id", channelId),
new XAttribute("name", channel),
new XElement("display-name", channel))
);
var xmlPath = ConfigurationManager.AppSettings["PastXmlFolderPath"] + "Day" + x + @"\" + channel + suffix + ".xml";
var xDoc2 = XDocument.Load(xmlPath);
doc.Root.Add(xDoc2.Descendants()
.DescendantNodes()
.OfType<XElement>()
.Where(n => n.Name.LocalName.Equals("programme")));
然而,重复的xml文档具有不需要的属性xmlns =&#34; tv:noNamespaceSchemaLocation&#34;在所有不在原始xml中的节点中。
当前输出:
<programme channel="W9" start="2016201002000 +0100" stop="2016201010000 +0100" xmlns="tv:noNamespaceSchemaLocation">
<length units="minutes">40</length>
<title>Intelligence *2013</title>
<category>Série</category>
</programme>
期望输出:
<programme channel="W9" start="2016201002000 +0100" stop="2016201010000 +0100">
<length units="minutes">40</length>
<title>Intelligence *2013</title>
<category>Série</category>
</programme>
如何在所有节点中摆脱这些额外的名字&#34; xmlns =&#34; tv:noNamespaceSchemaLocation&#34;。
由于