【发布时间】:2012-05-04 16:06:22
【问题描述】:
我正在尝试从另一个文件中删除然后将 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
有什么想法吗?谢谢!!
【问题讨论】:
标签: c# xml namespaces xelement