.NET Core中的System.XML等效函数

And*_*ijo 3 .net c# .net-core

我正在.NET Core中创建一个处理一些XML文件的应用程序.

在.NET 4.6中,我有以下代码:

var document = new XmlDocument(xml);
var node = document.SelectSingleNode("/SOMEPATH");
var value = node.GetValue("//SOMEOTHERPATH");
Run Code Online (Sandbox Code Playgroud)

显然SelectSingleNode,GetValue不再存在于System.XML中.

.NET Core中的等效函数是什么?

小智 7

https://github.com/dotnet/corefx/issues/17349

.Net Core 1.0和.Net Standard 1.3将SelectSingleNode作为System.Xml.XPath.XmlDocument包中的扩展方法(该页面未列出.Net Standard 1.3,但该程序包支持包),因此您需要添加对该包的引用以使用它.

.Net Core 2.0和.Net Standard 2.0将其更改回实例方法.

它出现ValueXmlNode可以通过以下方式访问XmlNode.Value.