xml文件如下
筛选出不是a的元素,在打印的时候只能打印OuterXml,XmlNode的InnerXml是空的
[Test] public void RemoveAppSettings() { var xPath = "/root/*[not(self::a)]"; var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var fileName = "test.xml"; var filePath = Path.Combine(desktopPath, fileName); var doc = new XmlDocument(); doc.Load(filePath); var nodeList = doc.SelectNodes(xPath); foreach (XmlNode node in nodeList) { Console.WriteLine(node.OuterXml); } }