I have been looking at similar questions and searching on-line but I cannot seem to find a a solution. What I am trying to do is select all the DOM elements in order ( etc.) and then put them into an arraylist or something.
currently I have
public void Parse()
{
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
// There are various options, set as needed
//htmlDoc.OptionFixNestedTags = true;
// filePath is a path to a file containing the html
htmlDoc.Load("Test.html");
// Use: htmlDoc.LoadHtml(xmlString); to load from a string (was htmlDoc.LoadXML(xmlString)
// ParseErrors is an ArrayList containing any errors from the Load statement
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
{
Console.WriteLine("There was an error parsing the HTML file");
}
else
{
if (htmlDoc.DocumentNode != null)
{
htmlDoc.DocumentNode.Descendants();
Console.WriteLine("document node not null");
//HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");
foreach (HtmlNode node in htmlDoc.DocumentNode.Descendants())
{
Console.WriteLine(node.Name);
}
}
}
}
The code out puts the name of the node (html, title, image, etc) but it outputs the closing tags as "#text". I assume this is because the tags start with a "/" How can I get a proper readout of all the DOM elements?