Markup context

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.

Element properties

Each item of current elements is a markup-element-event, which means that all of the following information is available about it:

So, for example, you can ask whether

  xmlns-name of element = xmlns-name of doctype
to establish if you are in the same namespace as the root document element, or
  occurrence of open element "item" = 1
to 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.

Attribute properties

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:

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
  • the public identifier, system identifier, notation, or the data attributes of any entity referenced by an attribute declared as entity can be accessed using the appropriate modifiers on %v
  • the same approach can be used to obtain the public or system identifier of any notation referenced by an attribute declared as notation

Global parse state

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.

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:

Prerequisite Concepts