Once an XML document has been opened, the following Parser methods may be used to examine the items contained within:
10 p .next() An XML document is represented by a tree-structure. Next returns the next item in the document at the current level of the tree within the current parent element. If there are no more such items, it returns nil .
p .down() Down descends into the element that has just been returned by next , which should be a Tag item. Subsequent items returned by next will be those within that tag.
p .up() Up moves up one level in the XML tree.
p .mark() Mark returns a mark that can be used to return later to the current position in the document. The underlying file must be seekable for this to work.
p .goto(m) Goes back to a previously marked position, m , in the document.
p .atmark(m) Atmark returns non-zero if the current position in the document is the same as that marked by m . The current tree level is ignored in the comparison.
p .str2mark(s) Str2mark turns a string as created by Mark.str back into a mark as returned by Parser.mark .
Tag A generic XML tag. Name names the tag, and attrs holds its attributes, if any.
Text Text represents inline text in the XML document. With the exception of text inside the tag named by preelem in open , any runs of white space are compressed to a single space, and white space at the start or end of the text is elided. Ch contains the resulting text; ws1 and ws2 are non-zero if there was originally white space at the start or end of the text respectively.
Process Process represents an XML document processing directive. Target is the processing instruction's target, and data holds the rest of the text inside the directive. XML stylesheet directives are recognised directly and have their own item type.
Doctype Doctype should only occur at the start of an xml document, and represents the type of the XML document.
Stylesheet Stylesheet represents an XML stylesheet processing request. The data of the processing request is parsed as per the RFC into attribute-value pairs.
Error If an unrecoverable error occurs processing the document, an Error item is returned holding the location ( loc ), and description ( msg ) of the error. This will be the last item returned by the parser.
The attribute-value pairs in Tag and Stylesheet items are held in an Atttributes adt, say a . A .all() yields a list holding all the attributes; a .get( name ) yields the value of the attribute name .
The location returned when an error is reported is held inside a Locator adt, which holds the line number on which the error occurred, the ``system id'' of the document (in this implementation, its file name), and the "public id" of the document (not currently used).
A Mark m may be converted to a string with m .str(); this enables marks to be written out to external storage, to index a large XML document, for example. Note that if the XML document changes, any stored marks will no longer be valid.
``Navigating Large XML Documents on Small Devices'' in Volume 2.