parsers::xml
Functions
Parse xml into a Document (slab DOM).
Never throws.
The returned document always has at least the root node (root). Malformed input is tolerated: unterminated tags/comments/CDATA consume to end-of-input, and a </x> with no matching open element is ignored rather than aborting the parse.
xml | the document text. |
the parsed document (root-only for empty/blank input).
O(n) in the length of xml for well-formed input; a run of & with no ; after it, or repeated unmatched end tags under deep nesting, degrade to O(n²).
the node slab and its strings on the heap (owned by the returned Document).
The document root's node id (its children are the top-level nodes).
doc | the document. |
the root node id (its children are the top-level nodes).
O(1).
none.
Whether id is a valid element node in doc.
doc | the document. |
id | the node id to test. |
true iff id is a valid element node.
O(1).
none.
The tag name of element id, or "" if id is not an element.
doc | the document. |
id | the element node id. |
the tag name, or "" if id is not an element.
O(1).
one result string.
Value of attribute name on element id, or "" if absent (or id is not an element).
doc | the document. |
id | the element node id. |
name | the attribute name. |
the attribute value, or "" if absent.
O(k) in the attribute count of id.
one result string.
ParsersXml.AttributeQuotingFormsWhether element id carries an attribute named name.
doc | the document. |
id | the element node id. |
name | the attribute name. |
whether id carries attribute name.
O(k) in the attribute count of id.
none.
The concatenated text of node id: for a text node, its own text; for an element, all descendant text in document order (like an XML .textContent).
doc | the document. |
id | the node id. |
the concatenated descendant text.
O(m) in the number of descendants of id.
the result string and a transient walk stack.
The child node ids of id, in document order (elements and text).
doc | the document. |
id | the node id. |
the child node ids in document order.
O(c) in the child count of id (the id list is copied).
the id list.
ParsersXml.FindFindallIterChildrenThe id of the first child element of id whose tag equals tag, or -1 if none.
(Direct children only — not descendants; use iter for the whole subtree.)
doc | the document. |
id | the parent node id. |
tag | the child tag to match. |
the first matching child element id, or -1.
O(c) in the direct-child count of id.
none.
ParsersXml.FindFindallIterChildrenThe ids of all direct child elements of id whose tag equals tag, in order.
doc | the document. |
id | the parent node id. |
tag | the child tag to match. |
the matching direct-child element ids.
O(c) in the direct-child count of id.
the result id list.
ParsersXml.FindFindallIterChildrenThe ids of every element in the subtree rooted at id (including id itself) whose tag equals tag, in document order — the analogue of an XML tree .iter(tag).
doc | the document. |
id | the subtree root node id. |
tag | the tag to match. |
the matching element ids in the subtree, in document order.
O(m) in the subtree size of id.
the result id list (and a transient walk stack).
ParsersXml.FindFindallIterChildren