Retrieve data from variable results view

arrays c# html-agility-pack

Question

I'm use thehtmlAgilityPack to get data from a table in such a manner

var text = from x in htmlDoc.DocumentNode.Descendants()
                   where x.Name == "p" && x.Attributes.Contains("class")
                   where x.Attributes["class"].Value == "cut"
                   select x.InnerText;

Debugging allows me to access theResults View This displays all the parsed information I need. But I'm having trouble figuring out how toreturn the array of data that has been processed.

How can I go about this?

1
1
10/26/2012 10:18:40 AM

Accepted Answer

There is nothing to cycle over or inspect the results of since all you are returning is a straightforward string to the variable text (ResultsView). To utilize ResultViews, keep in mind that you are not delivering an IEnumerable object.

I believe you need this.

var Result= from x in htmlDoc.DocumentNode.Descendants()
                   where x.Name == "p" && x.Attributes.Contains("class")
                   where x.Attributes["class"].Value == "cut"

foreach(var Item in Result){
//Access Item here.
}
1
10/26/2012 10:32:57 AM

Popular Answer

If unable toreturn , then I think the solution is fairly straightforward.

var text=from x in htmlDoc.DocumentNode.Descendants()
                       where x.Name == "p" && x.Attributes.Contains("class")
                       where x.Attributes["class"].Value == "cut"
                       select x.InnerText;
    //As the  above  query returns string,so you can check the result here..
    Label1.text=text.ToString()


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