Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an object in C# that allows for easy management of HTML DOM?

If I have a string that contains the html from a page I just got returned from an HTTP Post, how can I turn that into something that will let me easily traverse the DOM?

I figured HtmlDocument object would make sense, but it has no constructor. Are there any types that allow for easy management of HTML DOM?

Thanks,
Matt

like image 237
Matt Avatar asked Apr 20 '10 04:04

Matt


People also ask

What is object in C?

In C++, Object is a real world entity, for example, chair, car, pen, mobile, laptop etc. In other words, object is an entity that has state and behavior. Here, state means data and behavior means functionality. Object is a runtime entity, it is created at runtime.

Can we create object in C?

Create an ObjectIn C++, an object is created from a class. We have already created the class named MyClass , so now we can use this to create objects. To create an object of MyClass , specify the class name, followed by the object name.

Does C have object and class?

No, C doesn't have classes. That said, there are ways of simulating object-oriented programming in C - a quick Google search should yield some useful results.

Is a struct an object in C?

Short answer: Structs are value types. Classes(Objects) are reference types.


1 Answers

The HtmlDocument is an instance of a document that is already loaded by a WebBrowser control. Thus no ctor.

Html Agility Pack is by far the best library I have used to this purpose

An example from the codeplex wiki

HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href]"))
{
    HtmlAttribute att = link["href"];
    att.Value = FixLink(att);
}
doc.Save("file.htm");

The example shows loading of a file but there are overloads that let you load a string or a stream. 

like image 88
Sky Sanders Avatar answered Sep 19 '22 02:09

Sky Sanders