Using HTML.Tag
The HTML.Tag class, which is used to represent an HTML tag, is passed into many of the methods provided by the ParserCallback class that we just discussed. The HTML.Tag class provides four methods that provide basic information about the tag.
Method: breaksFlow
public boolean breaksFlow()
Returns true if this tag should cause a single line break.
Method: isBlock
public boolean isBlock()
Returns true if this tag should cause a double line break.
Method: isPreformatted
public boolean isPreformatted()
Returns true if white space should be preserved by this tag.
Method: toString
public String toString()
Convert the tag name to a string so that it can be handled as a string. This method converts only the name, it does not add the attributes nor the delimiting < and >.
The aforementioned methods are useful to get basic information about the type of tag you're dealing with. Usually, you will just want to know what type of tag it is. To do this, you should use the predefined tag constants defined in HTML.Tag. For example, to see if the tag stored in the variable t is an H1 tag, use the following code:
if( t==HTML.Tag.H1 )
Table 1 lists the 75 HTML tags recognized by the Swing HTML parser.
Table 1: HTML.Tag Constants
HTML.Tag.A |
HTML.Tag.ADDRESS |
HTML.Tag.APPLET |
HTML.Tag.AREA |
HTML.Tag.B |
HTML.Tag.BASE |
HTML.Tag.BASEFONT |
HTML.Tag.BIG |
HTML.Tag.BLOCKQUOTE |
HTML.Tag.BODY |
HTML.Tag.BR |
HTML.Tag.CAPTION |
HTML.Tag.CENTER |
HTML.Tag.CITE |
HTML.Tag.CODE |
HTML.Tag.COMMENT |
HTML.Tag.CONTENT |
HTML.Tag.DD |
HTML.Tag.DFN |
HTML.Tag.DIR |
HTML.Tag.DIV |
HTML.Tag.DL |
HTML.Tag.DT |
HTML.Tag.EM |
HTML.Tag.FONT |
HTML.Tag.FORM |
HTML.Tag.FRAME |
HTML.Tag.FRAMESET |
HTML.Tag.H1 |
HTML.Tag.H2 |
HTML.Tag.H3 |
HTML.Tag.H4 |
HTML.Tag.H5 |
HTML.Tag.H6 |
HTML.Tag.HEAD |
HTML.Tag.HR |
HTML.Tag.HTML |
HTML.Tag.I |
HTML.Tag.IMG |
HTML.Tag.IMPLIED |
HTML.Tag.INPUT |
HTML.Tag.ISINDEX |
HTML.Tag.KBD |
HTML.Tag.LI |
HTML.Tag.LINK |
HTML.Tag.MAP |
HTML.Tag.MENU |
HTML.Tag.META |
HTML.Tag.NOFRAMES |
HTML.Tag.OBJECT |
HTML.Tag.OL |
HTML.Tag.OPTION |
HTML.Tag.P |
HTML.Tag.PARAM |
HTML.Tag.PRE |
HTML.Tag.S |
HTML.Tag.SAMP |
HTML.Tag.SCRIPT |
HTML.Tag.SELECT |
HTML.Tag.SMALL |
HTML.Tag.STRIKE |
HTML.Tag.STRONG |
HTML.Tag.STYLE |
HTML.Tag.SUB |
HTML.Tag.SUP |
HTML.Tag.TABLE |
HTML.Tag.TD |
HTML.Tag.TEXTAREA |
HTML.Tag.TH |
HTML.Tag.TITLE |
HTML.Tag.TR |
HTML.Tag.TT |
HTML.Tag.U |
HTML.Tag.UL |
HTML.Tag.VAR |
|