Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 816
Keith Hill Avatar asked Dec 04 '25 02:12

Keith Hill


2 Answers

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.

like image 74
Ben Stine Avatar answered Dec 06 '25 16:12

Ben Stine


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.

like image 20
Jim Avatar answered Dec 06 '25 15:12

Jim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!