OmniMark is a streaming language and its parsers do not build a parse tree in memory. Instead, OmniMark provides powerful query facilities for retrieving information about the context of the markup currently parsed.
The current elements
shelf represents the stack of currently open elements. This allows you to make
complex queries about all open elements. You can iterate over all open elements using repeat over current
elements
, inquire about the current element depth with number of current elements
or access
any particular element by its item number. The shelf is not keyed nor directly
modifiable by the user.
OmniMark also provides means to quickly access a particular element from the current elements
shelf and to navigate through it.
The element qualifiers listed above can be combined to form more sophisticated queries. For example, the
expression
parent of ancestor "row" is "thead"tests whether there is an element in
current elements
other than the lastmost
, named row
, and whether the item
preceding it in current elements
is named thead
. Depending on the kind of markup you are
parsing, you can use this expression to establish if your element is a part of the innermost table heading.
Each item of current elements
is a markup-element-event
, which means that all of the
following information is available about it:
attributes
children
content is
declaration
last content is
last proper content is
last proper subelement is
last subelement is
name
occurrence
specified attributes
status is
status of last subelement is
usemap is
xmlns-name
So, for example, you can ask whether
xmlns-name of element = xmlns-name of doctypeto establish if you are in the same namespace as the root document element, or
occurrence of open element "item" = 1to find out if you are inside the first item of a list.
The most commonly accessed information is name of
, attributes of
and
specified attributes of
an element. OmniMark provides the shortcut attribute
notation for
accessing a single item of the attributes
shelf by name for any element. Format items %q
and
%v
allow for an even shorter notation for accessing the element's name and attributes, but only for the
current element.
The attributes
and specified attributes
shelves represent the declared and specified
attributes of each element. Each item of these two shelves may have the following properties you can inquire
about:
is cdata
and other queries about the declared attribute value type
is implied
is defaulted
is specified
repeat over attribute
can be used to iterate over tokenized attributes such as numbers
.
An attribute declared as entity
or notation
provides additional information
about the entity or notation it refers to:
name of
the entity or notation
data-attributes
notation
entity
can be accessed using the appropriate modifiers on %v
notation
Finally, OmniMark maintains certain information about the parse that is not associated with any particular element, attribute, or entity. This information is bound to the lifetime of the current parse.
#appinfo
#current-dtd
#doctype
#markup-error-count
#markup-parser
#markup-warning-count
#xmlns-names
number of current subdocuments
Whether #appinfo
, #current-dtd
, and #doctype
actually provide
information depends on the state of the parsing. They have a value assigned only if the document being parsed,
or the DTD being used to parse it, provides the information. In particular, this means they are never attached
in:
document-start
rules,
do sgml-parse
or do xml-parse
actions prior to a %c
operator or
suppress
action, unless a precompiled DTD is used,
do sgml-parse
or do xml-parse
actions after the %c
operator or
suppress
action, and
document-end
rules if errors occurred before this information could be determined.