HtmlAgilityPack using Linq for windows phone 8.1 platform

c# html-agility-pack linq windows-phone-8.1

Question

Since Windows Phone 8.1 does not yet support HTMLAgilityPack, explicitly mentioning it in the project was a workaround. However, this is not the only issue. I could needXPath to choose nodes for my previous project. I can see that now.HtmlDocumentNode.SelectNode() performs no longer (because of version compatibility may be).

What I used in my previous project was comparable to this.

HtmlNode parent = document.DocumentNode.SelectSingleNode("//ul[@class='songs-list1']");
HtmlNodeCollection x = parent.ChildNodes;

I discovered via my research on stackoverflow and google that Linq may still be used to choose nodes.

I'm looking for a piece of code that functions likeSelectNodes , SelectNode .

Putting theHtmlDocument Asynchronously is preferred.

1
4
8/12/2014 9:49:47 AM

Accepted Answer

This will work if you wanted to convert your existing XPath-based code to LINQ:

HtmlNode parent = document.DocumentNode
                          .Descendants("ul")
                          .FirstOrDefault(o => o.GetAttributeValue("class", "") 
                                                   == "songs-list1")
HtmlNodeCollection x = parent.ChildNodes;

However, you'd best not expect to discover any XPath-accepting methods in the HTMLAgilityPack version for Windows RT or Windows Phone 8.1 universal applications ("I'm looking for a piece of code that functions likeSelectNodes , SelectNode"): Metro Apps for Windows 8 and HTMLAgilityPack (answer by the author of HAP).

4
5/23/2017 11:47:15 AM

Popular Answer

Using the Element/s approach, you can achieve it:

        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(htmlString);
        var h6Nodes = from h6element in doc.DocumentNode.Element("body").Element("center").Elements("h6")
                      where h6element.Attributes["class"].Value.Equals("songs-list")                      
                      select h6element;

Assuming you have anything comparable,

string htmlString = @"<html>
<body>
<center>
<h6>Hello  </h6>
<h6>World!   </h6>
<h6 class=""songs-list"">
Insert that one song here
</h6>
</center>
</body>
</html>"

also obtaining the<h6> node containing a list of class songs.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow