Methods (600, 700, 900), apparatuses and computer program products are
disclosed for parsing and formatting a document encoded using a markup
language in a memory-constrained environment. The structure (100) of the
document is represented by a tree having one or more nodes (n1-n10). One
method (600) includes the steps of, for a current one of the nodes,
freeing memory occupied by any previously formatted one of the nodes upon
which formatting of the current node, according to a set of formatting
rules, is independent; and building a partial document tree (500) using
the current node and remaining previously formatted nodes upon which
formatting of the current node, according to the set of formatting rules,
is dependent. Another method includes the steps of obtaining information
about one or more nodes of the document using a lookahead parser, and
formatting the one or more nodes using the obtained information.