1

I need to find some way to find object from html file using Xpath or Html Selectors.

Since selectors are not supported in Html Agility Pack, I'm trying to use XPath.

Unfortunately it seems like SelectSingleNode(string somexpathvalue) is not available on Xamarin Forms. HtmlNode does not contain a definition of it.

I found in NuGet that I haven't got System.Xml.XPath installed. When I try to do it, I see an error:

Severity Code Description Project File Line Suppression State Error Could not install package 'System.Xml.XPath 4.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 0

Is there any way I could use SelectSingleNode without System.Xml.Xpath?

Piotrek
  • 10,919
  • 18
  • 73
  • 136

1 Answers1

1

No. Html Agility Pack (HAP) XPath support relies on .NET XPath implementation which is available in System.Xml.XPath*, and System.Xml.XPath itself doesn't have a version for Xamarin.Forms.

Your options might be to implement functionalities that relies on XPath in the corresponding platform specific projects (assuming you currently use portable Xamarin.Forms project approach), or use LINQ API of HAP instead of XPath to do the query. I believe most, if not all, query that you can write in XPath can be translated into LINQ.

*) Answer from the author of HAP : https://stackoverflow.com/a/15941723/2998271

**) Example XPath to LINQ translation : HtmlAgilityPack using Linq for windows phone 8.1 platform

Community
  • 1
  • 1
har07
  • 88,338
  • 12
  • 84
  • 137