Click here to Skip to main content
15,889,176 members
Articles / Programming Languages / Visual Basic
Article

MIL HTML Parser

Rate me:
Please Sign up or sign in to vote.
4.79/5 (77 votes)
30 Mar 20041 min read 394K   7.8K   154   74
A non-well-formed HTML parser for .NET

Introduction

This library produces a domain tree of a given HTML document, allowing the developer to navigate and change the document in an methodical way. In addition to the basic HTML production, this library can also be used to produce XHTML documents, as it includes an HTML 4 entity encoder. Included in this release is a demonstration application in VB.NET showing how to use the library. I hope that it is all fairly self-explanatory.

Background

This library was written to avoid having to convert a document into XML prior to reading, whilst preserving the distinct HTML qualities. This gets round some deployment issues I had with different platforms.

Using the code

The simplest way to use the code is to add it into your solution as a C# class library. There are no third-party dependencies so it is just a matter of adding the source files in. Alternatively, you can build the DLL and add it as a reference.

Points of Interest

The XHTML production is fairly basic - there is no built-in DTD checking. So far, I have had no problems in the generation, but I'm keen on getting that sorted.

History

  • 1.4
  • 1.3
    • Bugfix: <!DOCTYPE...> and <!...> now treated as comments
    • Bugfix: Malformed or incomplete attribute values causing infinite loop fixed
  • 1.2
    • Bugfix: <tag/> now handled properly
    • Bugfix: Parse errors of scripts
    • Bugfix: Parse errors of styles
    • HTML 4 entity encoding
    • DOM tree navigation
    • Basic node searching
    • HTML production
    • XHTML production (as per http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)
    • Added some component model stuff & comments
    • Hid the parser
  • 1.1
    • Initial release

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSgmlReader Pin
Jonathan de Halleux22-Mar-04 3:11
Jonathan de Halleux22-Mar-04 3:11 
GeneralSuggestions Pin
Stephane Rodriguez.22-Mar-04 2:53
Stephane Rodriguez.22-Mar-04 2:53 
GeneralRe: Suggestions Pin
GriffonRL22-Mar-04 10:06
GriffonRL22-Mar-04 10:06 
GeneralRe: Suggestions Pin
Stephane Rodriguez.22-Mar-04 18:59
Stephane Rodriguez.22-Mar-04 18:59 
GeneralRe: Suggestions Pin
GriffonRL22-Mar-04 20:46
GriffonRL22-Mar-04 20:46 
GeneralRe: Suggestions Pin
Stephane Rodriguez.22-Mar-04 22:13
Stephane Rodriguez.22-Mar-04 22:13 
GeneralRe: Suggestions Pin
GriffonRL22-Mar-04 22:38
GriffonRL22-Mar-04 22:38 
GeneralRe: Suggestions Pin
Stephane Rodriguez.22-Mar-04 23:10
Stephane Rodriguez.22-Mar-04 23:10 
GriffonRL wrote:
Mais je suis certain qu'on peut obtenir une très bonne librairie, avec SSL, authentifications, cookies et tout et tout et facile à utiliser

C'est marrant que tu dises ça, parce que ça pourrait laisser à penser qu'il manque quelque chose à HttpWebRequest alors que ce n'est pas le cas. Il y a un cookiecontainer, ce qu'il faut pour gérer le challenge response, la partie SSL est gérée en dessous comme pour n'importe quelle url de type https:// d'ailleurs. Donc je ne vois pas ce qui manque. Ah si, peut-être un parser html... Wink | ;-)


GriffonRL wrote:
Intéressant mais où en es-tu de ce projet ?

Je l'ai mis en pause, car d'autres produits stratégiques sont devenus prioritaires (taf).


GriffonRL wrote:
I was delighted to found it but I soon realised that the IE API was not fully implemented and was missing some important functions I need.

I think the debate could grow and grow forever since we are actually talking a large set of underlying layers of code including :
- an http client
- an http client that handles challenge response, ssl, cookies, ...
- an html parser, with/without malformed tolerance
- an html dom
- an html renderer
- an interactive UI on top of the html renderer, just like IE5.5 edit mode
- ...

I guess that if you really need all of that in your app, your best bet is to take IE. I am not sure though that most web-connected apps require much more than a simple rond-tripping html stuff. And may be when people try using IE and expect to use it like a stateful component, as in the rich client world, may be it's time to show them that they have probably taken not-so-good choices. When you know the lack of support for the simple "back button" scenario, it's funny to see how many people are still building apps on that...But eh, LH is supposed to sweep all that bricolage away.


GriffonRL wrote:
Second, it doesn't handle malformed HTML like IE does. It expects well formed HTML, so you might fail on a lot of badly designed pages

I didn't know. I still believe the source code can be the basis for code improvement. That's pretty much open source after all;
GeneralRe: Suggestions Pin
Anonymous22-Mar-04 20:49
Anonymous22-Mar-04 20:49 
GeneralAlready exists Pin
Rui Dias Lopes22-Mar-04 0:06
Rui Dias Lopes22-Mar-04 0:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.