我正在尝试从另一个文件中删除然后将 pageFooter 添加到 xml 文档:
XNamespace rep = "http://developer.cognos.com/schemas/report/8.0/";
//remove pageFooter
doc.Root.Descendants().Where(e=>e.Name == rep + "pageFooter").Remove();
//create and load pagefooter from file
XElement pageFooter = XElement.Load(@"C:\pageFooter.xml");
我得到了空的命名空间:
<pageFooter xmlns="">
<contents>
..............
我尝试了以下所有方法将命名空间添加到新元素,但没有任何效果:
XElement pagefooter = new XElement(rep+"pageFooter");
pageFooter = XElement.Load(@"C:\pageFooter.xml");
//this has no effect
pageFooter.Name = rep.GetName(pageFooter.Name.LocalName);
//this moves the xmlns="" to the next descendant, <contents>
pageFooter.Add(rep);
//this has no effect
pageFooter.SetAttributeValue("xmlns", rep);
//this results an empty pageFooter
有任何想法吗?谢谢!!