How to get all values inside a div as a string using HtmlAgilityPack

c# html html-agility-pack

Question

I have some HTML that I need to extract as a string, but just the div and its components.

 <div id=01>
    <div id-02>
      <label></labell>
      <input></input>
       //etc
     </div>
 </div>

How can I obtain every element inside of div 01 as one string?

The only other method I could find was to use the nodes, but it just gave me a list of HTMLNodes.

document.DocumentNode.SelectNodes("//*[contains(@class,'container')]").Descendants("div").Select(p => p.OuterHtml);
1
0
5/1/2018 2:42:14 AM

Popular Answer

var Node = document.DocumentNode.SelectNodes("//div[@id='01']").SingleOrDefault();
var target = Node.InnerHtml;

because I'm single For this id, I used SingleOrDefault.

1
10/8/2015 5:06:55 PM


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