Click here to Skip to main content
15,881,248 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 392.8K   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

 
Generalbug with filterindex in vb demo Pin
mgambrell17-Oct-05 13:37
mgambrell17-Oct-05 13:37 
GeneralI found some bugs. Pin
James S.F. Hsieh7-Sep-05 8:15
James S.F. Hsieh7-Sep-05 8:15 
GeneralAttribute with blank name and null value Pin
vnguyen91121-Jul-05 12:25
vnguyen91121-Jul-05 12:25 
Generaleats special characters Pin
Steven A. Lowe21-Mar-05 7:45
Steven A. Lowe21-Mar-05 7:45 
GeneralRe: eats special characters Pin
Steven A. Lowe21-Mar-05 9:38
Steven A. Lowe21-Mar-05 9:38 
Generalmistreats SSI and server scripts Pin
Steven A. Lowe15-Mar-05 11:21
Steven A. Lowe15-Mar-05 11:21 
GeneralRe: mistreats SSI and server scripts Pin
Steven A. Lowe17-Mar-05 5:20
Steven A. Lowe17-Mar-05 5:20 
GeneralBug in DOCTYPE Pin
arca_21-Feb-05 8:41
arca_21-Feb-05 8:41 
Try parsing the HTML at www.dn.se, your parser fails to correctly identify the <html> tag that follows directly after the <!DOCTYPE> tag. I get "html>" as a HtmlText node.
GeneralError when parsing &lt;a href=...&gt; on google.com Pin
marshall-cline15-May-04 9:11
marshall-cline15-May-04 9:11 
GeneralRe: Error when parsing &lt;a href=...&gt; on google.com Pin
Anwar A Moon13-Jun-05 0:20
Anwar A Moon13-Jun-05 0:20 
GeneralRe: Error when parsing &lt;a href=...&gt; on google.com Pin
garph030-Jul-07 22:01
garph030-Jul-07 22:01 
Questionvb/vb.net version? Pin
Huisheng Chen7-May-04 21:01
Huisheng Chen7-May-04 21:01 
GeneralSuggestions for changes Pin
giralt20-Apr-04 0:01
giralt20-Apr-04 0:01 
GeneralRe: Suggestions for changes - Thanks for the tip Pin
miliu21-Sep-04 6:36
miliu21-Sep-04 6:36 
GeneralRe: Suggestions for changes Pin
keremkusmezer3-Mar-05 22:11
keremkusmezer3-Mar-05 22:11 
Generalsevere problem! Pin
Huisheng Chen31-Mar-04 18:04
Huisheng Chen31-Mar-04 18:04 
GeneralThanks Pin
Aaron Eldreth31-Mar-04 3:44
Aaron Eldreth31-Mar-04 3:44 
GeneralAnother alternative (soon)... Pin
Martin Jericho25-Mar-04 12:43
Martin Jericho25-Mar-04 12:43 
GeneralRe: Another alternative (soon)... Pin
Bill Seddon27-Mar-04 21:56
Bill Seddon27-Mar-04 21:56 
GeneralRe: Another alternative (soon)... Pin
Aaron Jackson29-Sep-06 11:16
Aaron Jackson29-Sep-06 11:16 
GeneralSweet Work Pin
Jacob Slusser24-Mar-04 14:34
Jacob Slusser24-Mar-04 14:34 
GeneralRe: Sweet Work Pin
Martin Fuchs27-Mar-04 7:49
Martin Fuchs27-Mar-04 7:49 
GeneralRe: Sweet Work Pin
Jacob Slusser27-Mar-04 11:38
Jacob Slusser27-Mar-04 11:38 
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 

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.