Construct a DOM instance. The optional parameter indicates the initial number of nodes assigned to the freelist
Prepend an XML header to the document tree
Parse the given xml content, which will reuse any existing node within this document. The resultant tree is retrieved via the document 'tree' attribute
Return an xpath handle to query this document. This starts at the document root.
Reset the freelist. Subsequent allocation of document nodes will overwrite prior instances.
Implements a DOM atop the XML parser, supporting document parsing, tree traversal and ad-hoc tree manipulation.
The DOM API is non-conformant, yet simple and functional in style - locate a tree node of interest and operate upon or around it. In all cases you will need a document instance to begin, whereupon it may be populated either by parsing an existing document or via API manipulation.
This particular DOM employs a simple free-list to allocate each of the tree nodes, making it quite efficient at parsing XML documents. The tradeoff with such a scheme is that copying nodes from one document to another requires a little more care than otherwise. We felt this was a reasonable tradeoff, given the throughput gains vs the relative infrequency of grafting operations. For grafting within or across documents, please use the move() and copy() methods.
Another simplification is related to entity transcoding. This is not performed internally, and becomes the responsibility of the client. That is, the client should perform appropriate entity transcoding as necessary. Paying the (high) transcoding cost for all documents doesn't seem appropriate.
Parse example
API example
Note that the document tree() includes all nodes in the tree, and not just elements. Use doc.elements to address the topmost element instead. For example, adding an interior sibling to the prior illustration
Printing the name of the topmost (root) element:
XPath examples:
Note that path queries are temporal - they do not retain content across mulitple queries. That is, the lifetime of a query result is limited unless you explicitly copy it. For example, this will fail
The above will lose elements because the associated document reuses node space for subsequent queries. In order to retain results, do this
The above .dup is generally very small (a set of pointers only). On the other hand, recursive queries are fully supported
Typical usage tends to follow the following pattern, Where each query result is processed before another is initiated
Note that the parser is templated for char, wchar or dchar.