Retrieve data from variable results view

arrays c# html-agility-pack

Question

I am using the htmlAgilityPack to retrieve data from a table as so-

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;

On debugging I can access the Results View which shows all the parsed data I need to access. However I cannot figure out how to return the data array that has been parsed.

How can I do this?

Accepted Answer

What you are returning is a simple string back to the variable text,so there is nothing to iterate or view the results(ResultsView).Remember you are not returning a IEnumerable object to use ResultViews.

I think 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.
}

Popular Answer

If,not able to return is only your problem then I believe it's quite simple..

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()


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why