Windows 10 通用 XmlNode 不包含 SelectSingleNode 的定义 [英] Windows 10 universal XmlNode does not contain a definition for SelectSingleNode

查看:32
本文介绍了Windows 10 通用 XmlNode 不包含 SelectSingleNode 的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Windows 10 Visual Studios C#.我正在尝试从 XML 文件中读取数据,并且已经阅读了程序集文档:

Using Windows 10 Visual Studios C#. I am trying to read from an XML file and I have read through the assembly documentation:

https://msdn.microsoft.com/en-us/library/system.xml.xmlnode(v=vs.110).aspx

文档明确指出SelectSingleNode"和SelectNodes"是可用方法,但它们没有出现在预测列表中,当我尝试使用它们时,我收到错误消息XmlNode 不包含 SelectSingleNode 的定义".

The documentation clearly says that 'SelectSingleNode' and 'SelectNodes' are available methods but they don't appear in the predictive list and when trying to use them I get the error message 'XmlNode does not contain a definition for SelectSingleNode'.

我一直在寻找解决方案,但似乎找不到解决方案.

I have been searching for a solution to this for a while and I can't seem to find a solution.

(是的,我已经包含了 System.Xml,我什至尝试使用 MS 的示例代码,但它产生了同样的问题)

(yes, I have included System.Xml and I even tried using the sample code from MS and it produces the same problem)

推荐答案

我目前遇到了同样的问题,但已经开始寻找一些信息.根据我对 UWP 的了解,您将需要使用 XDocument 和 LINQ,它们是命名空间的一部分:System.Xml.Linq

I am currently running into the same issue, but have started to find some information. From what I understand about UWP you will need to use XDocument and LINQ, part of the namespace: System.Xml.Linq

MSDN 参考

linq 示例的代码片段:

A code snippet of linq example:

XDocument loadedData = XDocument.Load(XMLPath);
var data = from query in loadedData.Descendants("Order")                      
   select new Countries
   {
       OrderId  = (string)query.Attribute("OrderID") ,
       OrderTotal = (string)query.Attribute("OrderTotal"),
       Customer = (string)query.Attribute("Customer"),
       Phone = (string)query.Attribute("Phone")
   };
DataGrid1.ItemsSource = data;

这是我为同一问题找到的最佳解决方案.

This has been the best solution I have found to the same question.

这篇关于Windows 10 通用 XmlNode 不包含 SelectSingleNode 的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆