# Class HTMLParser

java.lang.Object
com.codename1.xml.XMLParser
com.codename1.ui.html.HTMLParser

public class HTMLParser extends XMLParser
The HTMLParser class is used to parse an XHTML-MP 1.0 document into a DOM object (Element). Unsupported tags and attributes as well as comments are dropped in the parsing process. The parser is also makes use of CSSParser for external CSS files, embedded CSS segments and CSS within the 'style' attribute.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HTMLParser()`
  Constructs a new instance of HTMLParser

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected String`
  `convertCharEntity(String charEntity)`
  Overrides XMLParser.convertCharEntity to add in HTML char entities
  `protected Element`
  `createNewElement(String name)`
  Overrides XMLParser.createNewElement to return an HTMLElement instance
  `protected Element`
  `createNewTextElement(String text)`
  Overrides XMLParser.createNewTextElement to return an HTMLElement instance
  `protected String`
  `getSupportedStandardName()`
  {Returns a string identifying the document type this parser supports.
  `protected boolean`
  `isEmptyTag(String tagName)`
  Checks whether the specified tag is an empty tag as defined in EMPTY_TAGS
  `protected boolean`
  `isSupported(Element element)`
  Overrides the Element.isSupported to let the parser know which tags are supported in XHTML-MP 1.0
  `HTMLElement`
  `parseHTML(InputStreamReader isr)`
  A convenience method that casts the returned type of the parse method to HTMLElement.
  `protected void`
  `parseTagContent(Element element, Reader is)`
  Overrides XMLParser.parseTagContent to enable embedded CSS segments (Style tags)
  `protected boolean`
  `shouldEvaluate(Element element)`
  Overrides the Element.shouldEvaluate method to return false on the script tag.

  ### Methods inherited from class XMLParser

  `addCharEntitiesRange, addCharEntity, attribute, endTag, eventParser, isCaseSensitive, isWhiteSpace, notifyError, parse, parseCommentOrXMLDeclaration, parseTag, setCaseSensitive, setIncludeWhitespacesBetweenTags, setParserCallback, startTag, textElement`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### HTMLParser

    public HTMLParser()
    Constructs a new instance of HTMLParser

- ## Method Details

  - ### parseTagContent

    protected void parseTagContent(Element element, Reader is) throws IOException

    Overrides XMLParser.parseTagContent to enable embedded CSS segments (Style tags)

    ###### Parameters

    - `element`: The current parent element

    - `is`: The reader containing the XML

    ###### Throws

    - `IOException`: if an I/O error in the stream is encountered
    Overrides:
      `parseTagContent` in class `XMLParser`
    Throws:
      `IOException`

  - ### createNewElement

    protected Element createNewElement(String name)

    Overrides XMLParser.createNewElement to return an HTMLElement instance

    ###### Parameters

    - `name`: The HTMLElement's name

    ###### Returns

    a new instance of the names HTMLElement

    Overrides:
      `createNewElement` in class `XMLParser`

  - ### createNewTextElement

    protected Element createNewTextElement(String text)

    Overrides XMLParser.createNewTextElement to return an HTMLElement instance

    ###### Parameters

    - `text`: The HTMLElement's text

    ###### Returns

    a new instance of the HTMLElement

    Overrides:
      `createNewTextElement` in class `XMLParser`

  - ### convertCharEntity

    protected String convertCharEntity(String charEntity)

    Overrides XMLParser.convertCharEntity to add in HTML char entities

    ###### Parameters

    - `charEntity`: The char entity to convert

    ###### Returns

    A string containing a single char, or the original char entity string (with & and ;) if the char entity couldn't be resolved

    Overrides:
      `convertCharEntity` in class `XMLParser`

  - ### isEmptyTag

    protected boolean isEmptyTag(String tagName)

    Checks whether the specified tag is an empty tag as defined in EMPTY_TAGS

    ###### Parameters

    - `tagName`: The tag name to check

    ###### Returns

    true if that tag is defined as an empty tag, false otherwise

    Overrides:
      `isEmptyTag` in class `XMLParser`

  - ### parseHTML

    public HTMLElement parseHTML(InputStreamReader isr)

    A convenience method that casts the returned type of the parse method to HTMLElement. Basically calling this method is simlar to calling parse and casting to HTMLElement.

    ###### Parameters

    - `isr`: The input stream containing the HTML

    ###### Returns

    The HTML document

  - ### getSupportedStandardName

    protected String getSupportedStandardName()

    {

    Returns a string identifying the document type this parser supports. This should be overriden by subclassing parsers.

    ###### Returns

    a string identifying the document type this parser supports.

    }
    Overrides:
      `getSupportedStandardName` in class `XMLParser`

  - ### isSupported

    protected boolean isSupported(Element element)

    Overrides the Element.isSupported to let the parser know which tags are supported in XHTML-MP 1.0

    ###### Returns

    true if the tag is a supported XHTML Mobile Profile 1.0 tag, false otherwise

    Overrides:
      `isSupported` in class `XMLParser`

  - ### shouldEvaluate

    protected boolean shouldEvaluate(Element element)

    Overrides the Element.shouldEvaluate method to return false on the script tag. The script tag should be skipped entirely, since it may contain characters like greater-than and lesser-than which may break the HTML All other tags are evaluated (i.e. added including all their children to the tree), even if not supported (But of course their functionality is ignored by HTMLComponent)

    ###### Returns

    false if this is the SCRIPT tag, true otherwise

    Overrides:
      `shouldEvaluate` in class `XMLParser`