This class provides a concrete and efficient implementation of the Reader protocol.

Synopsis

Declared in <balxml_minireader.h>

class MiniReader
    : public Reader

Base Classes

Name

Description

Reader

This abstract class defines an interface for fast, forward‐only access to XML data. An object belonging to a derived‐class implementation of this protocol is required to be re‐usable, such that a new XML document can be parsed using the same reader object by calling close followed by another open.

Type Aliases

Name

Description

StreamBufPtr

Managed pointer to a bsl::streambuf used for external entity input.

XmlResolverFunctor

Type for a user supplied functor that finds and opens an external resource for the specified location and/or namespaceUri and returns that resource as a managed pointer to a stream. The location argument specifies the location of the external resource and is typically a filename or a URI, depending on the context. The namespaceUri argument always refers to the XML namespace of the entity to be resolved. A conforming functor returns an empty managed pointer if it cannot resolve the resource. For example, the reader may use a resolver to open an external entity, even if the reader does not do validation (see definition of <!ENTITY> in the XML standard). Note that either argument can be NULL in situations where its value is not needed or can be computed from the other argument.

Enums

Name

Description

NodeType

Node types returned by nodeType, representing XML syntactic constructs within a document. Not every Reader implementation distinguishes all node types.

Member Functions

Name

Description

MiniReader [constructor]

Constructors

~MiniReader [destructor] [virtual]

Destroy this reader and release resources.

advanceToEndNode [virtual]

Skip all the sub elements of the current node and position the reader on its corresponding end node. While skipping ensure that the elements being skipped are well‐formed and do not contain any parsing errors. Return 0 on successful skip, and a negative number otherwise (error). The behavior is undefined unless balxml::Reader::e_NODE_TYPE_ELEMENT == node.type(). Note that each call to advanceToEndNode invalidates strings and data structures returned when Reader accessors were called for the "prior node". E.g., the pointer returned from nodeName for this node won't be valid once advanceToEndNode is called. Note that this method leaves the reader pointing to an end node, so calling one of the advanceToEndNode immediately after will not advance the reader further (first call advanceToNextNode before calling the advanceToEndNode function again).

advanceToEndNodeRaw [virtual]

Skip all the sub elements of the current node and position the reader on its corresponding end node, and (unlike advanceToNextNode) perform no checks to ensure that the elements being skipped are well‐formed and that they do not contain any parsing errors. Return 0 on successful skip, and a negative number otherwise (error). The behavior is undefined unless balxml::Reader::e_NODE_TYPE_ELEMENT == node.type(). Note that each call to advanceToEndNodeRaw invalidates strings and data structures returned when Reader accessors were called for the "prior node". E.g., the pointer returned from nodeName for this node will not be valid once advanceToEndNodeRaw is called. Note that this method leaves the reader pointing to an end node, so calling one of the advanceToEndNodeRaw immediately after will not advance the reader further (first call advanceToNextNode before calling the advanceToEndNodeRaw function again).

advanceToEndNodeRawBare [virtual]

Skip all the sub elements of the current node and position the reader on its corresponding end node, and (unlike advanceToNextNode) perform no checks to ensure that the elements being skipped are well‐formed and that they do not contain any parsing errors. Unlike advanceToEndNodeRaw this method does not expect (allow) comments or CDATA nodes in the input XML, in other words it is expecting "bare" XML. Return 0 on successful skip, and a negative number otherwise (error). The behavior is undefined unless balxml::Reader::e_NODE_TYPE_ELEMENT == node.type(). The behavior is also undefined if the input XML contains comment or CDATA nodes. Note that each call to advanceToEndNodeRawBare invalidates strings and data structures returned when Reader accessors were called for the "prior node". E.g., the pointer returned from nodeName for this node will not be valid once advanceToEndNodeRawBare is called. Note that this method leaves the reader pointing to an end node, so calling one of the advanceToEndNodeRawBare immediately after will not advance the reader further (first call advanceToNextNode before calling the advanceToEndNodeRawBare function again).

advanceToNextNode [virtual]

Move to the next node in the data steam created by open thus allowing the node's properties to be queried via the Reader accessors. Return 0 on successful read, 1 if there are no more nodes to read, and a negative number otherwise. Note that each call to advanceToNextNode invalidates strings and data structures returned when Reader accessors were called for the "prior node". E.g., the pointer returned from nodeName for this node will not be valid once advanceToNextNode is called. Note that the reader will not be on a valid node until the first call to advanceToNextNode after the reader is opened.

close [virtual]

Close the reader. Most, but not all state is reset. Specifically, the XML resource resolver and the prefix stack remain. The prefix stack shall be returned to the stack depth it had when setPrefixStack was called. Call the method open to reuse the reader. Note that close invalidates all strings and data structures obtained via Reader accessors. E.g., the pointer returned from nodeName for this node will not be valid once close is called.

documentEncoding [virtual]

Return the document encoding or NULL on error. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid when close is called or the reader is destroyed.

dumpNode

Print the information about the current node to the specified output os stream.

errorInfo [virtual]

Return a reference to the non‐modifiable error information for this reader. The returned value becomes invalid when close is called or the reader is destroyed.

getColumnNumber [virtual]

Return the current column number within the input stream. The current column number is the number of characters since the last newline was read by the reader plus one, i.e., the first column of each line is column number one. Return 0 if not available. Note that a derived‐class implementation is not required to count columns and may just return 0.

getCurrentPosition

Return the current scanner position as offset from the beginning of document.

getLineNumber [virtual]

Return the current line number within the input stream. The current line is the last line for which the reader has not yet seen a newline. Lines are counted starting at one from the time a stream is provide to open. Return 0 if not available. Note that a derived‐class implementation is not required to count lines and may just return 0.

isEmptyElement [virtual]

Return true if the current node is an element (i.e., node type is NODE_TYPE_ELEMENT) that ends with />; and false otherwise. Note that will be considered empty but will not.

isError

Return true if the derived object encountered a error. This method is equivalent to a call to errorInfo().isError();

isFatalError

Return true if the derived object encountered a fatal error. This method is equivalent to a call to errorInfo().isFatalError();

isOpen [virtual]

Return true if open was called successfully and close has not yet been called and false otherwise.

isWarning

Return true if the derived object encountered a warning. This method is equivalent to a call to errorInfo().isWarning();

lookupAttribute

lookupAttribute overloads

nodeBaseUri [virtual]

Return the base URI name of the current node if the current node has a base URI and NULL otherwise. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid upon the next advanceToNextNode, when close is called or the reader is destroyed.

nodeDepth [virtual]

Return the nesting depth of the current node in the XML document. The root node has depth 0.

nodeEndPosition

Return the byte position within the document corresponding to the byte following after the last byte of the current node.

nodeHasValue [virtual]

Return true if the current node has a value and false otherwise.

nodeLocalName [virtual]

Return the local name of the current node if the current node has a local name and NULL otherwise. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid upon the next advanceToNextNode, when close is called or the reader is destroyed.

nodeName [virtual]

Return the qualified name of the current node if the current node has a name and NULL otherwise. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid upon the next advanceToNextNode, when close is called or the reader is destroyed.

nodeNamespaceId [virtual]

Return the namespace ID of the current node if the current node has a namespace id and a negative number otherwise.

nodeNamespaceUri [virtual]

Return the namespace URI name of the current node if the current node has a namespace URI and NULL otherwise. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid upon the next advanceToNextNode, when close is called or the reader is destroyed.

nodePrefix [virtual]

Return the prefix name of the current node if the correct node has a prefix name and NULL otherwise. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid upon the next advanceToNextNode, when close is called or the reader is destroyed.

nodeStartPosition

Return the byte position within the document corresponding to the first byte of the current node.

nodeType [virtual]

Return the node type of the current node if the reader isOpen and has not encounter an error and Reader::NONE otherwise.

nodeValue [virtual]

Return the value of the current node if the current node has a value and NULL otherwise. The returned pointer is owned by this object and must not be modified or deallocated by the caller. The returned pointer becomes invalid upon the next advanceToNextNode, when close is called or the reader is destroyed.

numAttributes [virtual]

Return the number of attributes for the current node if that node has attributes and 0 otherwise.

open

open overloads

options [virtual]

Return the option flags.

prefixStack [virtual]

Return a pointer to the modifiable prefix stack that is used by this reader to manage namespace prefixes or 0 if namespace support is disabled. The behavior is undefined if the returned prefix stack is augmented in any way after calling open and before calling close.

resolver [virtual]

Return the external XML resource resolver.

setOptions [virtual]

Set the options to the flags in the specified flags. The options for the reader are persistent, i.e., the options are not reset by close. The behavior is undefined if this method is called after calling open and before calling close.

setPrefixStack [virtual]

Set the prefix stack to the stack at the specified prefixes address or disable prefix stack support if prefixes == 0. This stack is used to push and pop namespace prefixes as the parse progresses, so that, at any point, the stack will reflect the set of active prefixes for the current node. It is legitimate to pass a stack that already contains prefixes, these prefixes shall be preserved when close is called, i.e., the prefix stack shall be returned to the stack depth it had when setPrefixStack was called. The behavior is undefined if this method is called after calling open and before calling close.

setResolver [virtual]

Set the external XML resource resolver to the specified resolver. The XML resource resolver is used by the balxml_reader to find and open an external resources (See the XmlResolverFunctor typedef for more details). The XML resource resolver remains valid; it is not affected by a call to close and should be available until the reader is destroyed. The behavior is undefined if this method is called after calling open and before calling close.

Static Member Functions

Name

Description

nodeTypeAsString

Return a string representation for the specified nodeType code or "(* UNKNOWN NODE TYPE *)" if nodeType is not one of the values enumerated in NodeType.

Friends

Name

Description

BloombergLP::balxml::MiniReader::Node

Created with MrDocs