java.lang.Object | |
↳ | javax.swing.text.html.parser.Parser |
![]() |
A simple DTD-driven HTML parser. The parser reads an HTML file from an InputStream and calls various methods (which should be overridden in a subclass) when tags and data are encountered.
Unfortunately there are many badly implemented HTML parsers out there, and as a result there are many badly formatted HTML files. This parser attempts to parse most HTML files. This means that the implementation sometimes deviates from the SGML specification in favor of HTML.
The parser treats \r and \r\n as \n. Newlines after starttags and before end tags are ignored just as specified in the SGML/HTML specification.
The html spec does not specify how spaces are to be coalesced very well. Specifically, the following scenarios are not discussed (note that a space should be used here, but I am using   to force the space to be displayed):
'<b>blah <i> <strike> foo' which can be treated as: '<b>blah <i><strike>foo'
as well as: '<p><a href="xx"> <em>Using</em></a></p>' which appears to be treated as: '<p><a href="xx"><em>Using</em></a></p>'
If strict
is false, when a tag that breaks flow,
(TagElement.breaksFlows
) or trailing whitespace is
encountered, all whitespace will be ignored until a non whitespace
character is encountered. This appears to give behavior closer to
the popular browsers.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
dtd | |||||||||||
strict | This flag determines whether or not the Parser will be strict in enforcing SGML compatibility. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parse an HTML stream, given a DTD.
| |||||||||||
Parses th Document Declaration Type markup declaration.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Handle an end tag.
| |||||||||||
Invoke the error handler.
| |||||||||||
Called when an HTML comment is encountered.
| |||||||||||
Called when an empty tag is encountered.
| |||||||||||
Called when an end tag is encountered.
| |||||||||||
An error has occurred.
| |||||||||||
Called when a start tag is encountered.
| |||||||||||
Called when PCDATA is encountered.
| |||||||||||
Called when an HTML title tag is encountered.
| |||||||||||
Makes a TagElement.
| |||||||||||
Marks the first time a tag has been seen in a document
| |||||||||||
Parse markup declarations.
| |||||||||||
Handle a start tag.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
This flag determines whether or not the Parser will be strict in enforcing SGML compatibility. If false, it will be lenient with certain common classes of erroneous HTML constructs. Strict or not, in either case an error will be recorded.
Parses th Document Declaration Type markup declaration. Currently ignores it.
IOException |
---|
Handle an end tag. The end tag is popped from the tag stack.
Called when an HTML comment is encountered.
Called when an empty tag is encountered.
ChangedCharSetException |
---|
Called when PCDATA is encountered.
Called when an HTML title tag is encountered.
Parse markup declarations. Currently only handles the Document Type Declaration markup. Returns true if it is a markup declaration false otherwise.
IOException |
---|
Handle a start tag. The new tag is pushed onto the tag stack. The attribute list is checked for required attributes.
ChangedCharSetException |
---|