Skip navigation links
SAP NetWeaver 7.50 SP 22 KMC

Package com.sapportals.wcm.util.html

Contains classses that handle the parsing of HTML.

See: Description

Package com.sapportals.wcm.util.html Description

Contains classses that handle the parsing of HTML.

Package Specification

The package offers two styles of HTML parsing: push and pull.

Pull Parsing

HtmlTokenizer and HtmlTag implement a "pull"-style parsing of HTML documents.

The client of HtmlTokenizer calls next() until the end of the document is reached. The tokenizer returns the type of the next parsed token and also its string content. A client can then use HtmlTag to access string content of a TAG token in a structured way.

Push Parsing

IHTMLReader and IHTMLContentHandler are the basic interfaces for "push"-tyle parsing of HTML documents.

IHTMLReader follows closely the SAX API approach. A content handler is installed in a reader which receives events for every parsed document part. A client of IHTMLReader invokes parse() on the reader whereas the complete document is read. During this, all events are sent to the installed content handler.

As a mixture betwenn "push" and "pull", IHTMLReader also offers a way of "controled-push" parsing. The client can invoke parseNextEvent(), whereas the reader sends one event to the content handler and returns to the client afterwards.

Character Encoding

Both push and pull parsers can detect the character encoding of the given HTML document. Both parsers use the <meta> tag as explained here.

Filtering

IHTMLFilter is a general filter interface for the push parser. Filters can be chained and appear as a IHTMLReader to the client. Each filter installs itself as content handler in its IHTMLReader.
There is a default implementation in HTMLFilterImpl which implements the identity function, e.g. all events are forwarded unchanged.

Output

The output of a filter/reader chain can be sent to OutputStream or Writer by using the HTMLStreamWriter. Likewise the output from a filter/reader can be used as InputStream to read from by using the HTMLInputStream.

XHTML

It is possible to parse XHTML or even plain XML documents with the parsers in this package. By default, both parsers make no attempt to validate the document or enforce any structure (not even that the first tag is <html>). The basic working assumption for the parsers is: "report anything which does not look like a tag as text token/event."

Both parsers do not care about namespace declarations (reporting them as attributes on the tag/element) or even namespace prefixes. IHTMLReader elements only have a name where the prefix is part of. As a consequence XHTML documents which use a non-empty namespace prefix for the xhtml namespace, will not be properly handled by content handlers.

Related Documentation

Skip navigation links
SAP NetWeaver 7.50 SP 22 KMC

Copyright 2021 SAP SE Complete Copyright Notice