class

XParser

@Js
class XParser : Obj

XParser is a simple, lightweight XML parser. It may be used as a pull parser by iterating through the element and text sections of an XML stream or it may be used to read an entire XML tree into memory as XElems.

constructors make

Construct input stream to read

fields col

Current one based column number

depth

Get the depth of the current element with the document

line

Current one based line number

doc

Get the root document node

nodeType

Get the current node type constant which is always the result of the last call to next

methods elem

Get the current element if nodeType is elemStart or elemEnd

next

Advance the parser to the next node and return the node type

parseElem

Parse the current element entirely into memory as a tree of XElems and optionally close the underlying input stream

elemAt

Get the element at the specified depth

parseDoc

Parse the entire document into memory as a tree of XElems and optionally close the underlying input stream

pi

if the current node type is pi return the XPi instance otherwise return null

skip

Skip parses all the content until reaching the end tag of the specified depth

text

If the current type is text the XText instance used to store the character data

close

Close the underlying input stream

close Bool close()

Close the underlying input stream. Return true if the stream was closed successfully or false if the stream was closed abnormally.

col Int : col

Current one based column number.

depth Int : depth

Get the depth of the current element with the document. A depth of zero indicates the root element. A depth of -1 indicates a position before or after the root element.

doc XDoc : doc

Get the root document node.

elem XElem? elem()

Get the current element if nodeType is elemStart or elemEnd. If nodeType is text or pi then this is the parent element. After elemEnd this XElem instance is no longer valid and will be reused for further processing. If depth is -1 return null.

elemAt XElem elemAt(Int depth)

Get the element at the specified depth. Depth must be between 0 and depth inclusively. Calling elemAt(0) will return the root element and elemAt(depth) returns the current element. If depth is invalid IndexErr is thrown.

line Int : line

Current one based line number.

make new make(InStream in)

Construct input stream to read.

next XNodeType? next()

Advance the parser to the next node and return the node type. Return the current node type:

nodeType XNodeType? : nodeType

Get the current node type constant which is always the result of the last call to next. Node type will be:

parseDoc XDoc parseDoc(Bool close)

Parse the entire document into memory as a tree of XElems and optionally close the underlying input stream.

parseElem XElem parseElem(Bool close)

Parse the current element entirely into memory as a tree of XElems and optionally close the underlying input stream.

pi XPi? pi()

if the current node type is pi return the XPi instance otherwise return null.

skip Void skip(Int toDepth)

Skip parses all the content until reaching the end tag of the specified depth. When this method returns, the next call to next will return the node immediately following the end tag.

text XText? text()

If the current type is text the XText instance used to store the character data. After a call to next this XText instance is no longer valid and will be reused for further processing. If the current type is not text then return null.

Haxall 4.0.5 ∙ 24-Feb-2026 14:33 EST