2017-04-05 58 views
2

我正在.NET Core中创建一个应用程序,它将处理一些XML文件。.NET Core中的System.XML等效函数

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

var document = new XmlDocument(xml); 
var node = document.SelectSingleNode("/SOMEPATH"); 
var value = node.GetValue("//SOMEOTHERPATH"); 

显然SelectSingleNodeGetValue不存在了System.XML了。

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

+0

http://stackoverflow.com/questions/35089399/selectsinglenode-is-giving-compilation-error-in-dnx-core-5-0 –

回答

6

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

的.Net核心1.0和.Net标准1.3具有的SelectSingleNode作为System.Xml.XPath.XmlDocument包的扩展方法(在页面未列出的.Net标准1.3,但该软件包在其上受支持),因此您需要添加对该软件包的引用才能使用它。

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

似乎一个XmlNodeValue可以通过XmlNode.Value访问。

+0

新增'“System.Xml.XPath.XmlDocument”:“4.3。 0“作为依赖,方法回来了。谢谢 – AndreFeijo