如何在不知道属性和值的情况下在XDocument中添加名称空间?

时间:2012-10-22 03:24:23

标签: linq-to-xml

例如

           XmlNamespaceManager nsmgr = new XmlNamespaceManager(myxmldocument.NameTable);
           nsmgr.AddNamespace("xdp", "http://ns.adobe.com/xdp/");
           nsmgr.AddNamespace("config", "http://www.xfa.org/schema/xci/1.0/");

同样如何在XDocument中添加?

1 个答案:

答案 0 :(得分:0)

string s = myXDocument.ToString();//my XDocument  corresponds to our existing XDocument
XPathDocument xpath = new XPathDocument(new StringReader(s));
        XPathNavigator pathnavigator= xpath .CreateNavigator();
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(pathnavigator.NameTable);