简体   繁体   中英

Windows 10 universal XmlNode does not contain a definition for SelectSingleNode

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

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.

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

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 reference

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.

It is possible you are looking at the System.Xml versions still, which when referenced, do not bring in those methods.

If you rename your System.Xml to Windows.Data.Xml.Dom (namespace), then you won't have XmlNode anymore. It's now IXmlNode. This interface has the SelectSingleNode and SelectNodes you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM