#include <Pt/Xml/XmlReader.h>
Reads XML as a Stream of XML Nodes. More...
Inherits NonCopyable.
Public Member Functions | |
XmlReader () | |
Default Constructor. | |
XmlReader (InputSource &is) | |
Construct with input source. | |
XmlReader (XmlResolver &r, InputSource &is) | |
Construct with resolver and input source. | |
~XmlReader () | |
Destructor. | |
void | addInput (InputSource &in) |
Adds an external input source. More... | |
Node * | advance () |
Process availabe data from underlying input source. | |
InputIterator | current () |
Returns an iterator to the current node. | |
std::size_t | depth () const |
Returns the XML tree depth. | |
DocTypeDefinition & | dtd () |
Returns current DTD of the document. | |
const DocTypeDefinition & | dtd () const |
Returns current DTD of the document. | |
InputIterator | end () const |
Returns an iterator to the end of the document. | |
Node & | get () |
Get current node. | |
InputSource * | input () |
Returns the current input source or nullptr if none is set. | |
std::size_t | line () const |
Returns the current line of the primary input source. | |
std::size_t | maxSize () const |
Returns the number of characters the parser may allocate. | |
Node & | next () |
Get next node. | |
void | reportCData (bool value) |
Configures the parser to report CDATA sections. | |
void | reportComments (bool value) |
Configures the parser to report comments. | |
void | reportDocType (bool value) |
Configures the parser to report DOCTYPEs. | |
void | reportEntityReferences (bool value) |
Configures the parser to report entity references. | |
void | reportProcessingInstructions (bool value) |
Configures the parser to report processing instructions. | |
void | reportStartDocument (bool value) |
Configures the parser to report the start of the document. | |
void | reset () |
Clears the reader state and input. More... | |
void | reset (InputSource &is) |
Starts parsing with an input source. More... | |
XmlResolver * | resolver () const |
Returns the resolver or nullptr is none was set. | |
void | setChunkSize (std::size_t n) |
Sets the max size of a characters block. More... | |
void | setMaxInputDepth (std::size_t n) |
Sets the max expansion depth of input sources. | |
void | setMaxSize (std::size_t n) |
Sets the max number of characters the parser may allocate. | |
std::size_t | usedSize () const |
Returns the number of characters the parser has allocated. | |
This class operates on an input source from which XML character data is read and parsed. The content of the XML document is reported as XML nodes.
The parser will only parse the XML document as far as the user read data from it. To acces the current node the method get() can be used. To parse and read the next node the method next() can be used. Only when next() or any corresponding method or operator is called, the next chunk of XML input data is parsed.
The current XML node can be read using get(). Every call to next() will parse the next node, position the cursor to the next node and return the parsed node. The returned value is of type Node, which is the super-class for all XML node classes.
Depending on the type, the generic node object may be cast to the more concrete node object. For example a Node object with a node type of Node::StartElement can be cast to StartElement.
Parsing using next() will continue until the end of the document is reached which will result in a EndDocument node to be returned by next() and get().
This class also provides the method current() to obtain an iterator which basically works the same way like using using get() and next() directly. The iterator can be set to the next node by using the ++ operator. The current node can be accessed by dereferencing the iterator.
void addInput | ( | InputSource & | in | ) |
This method can be used to add additional input streams e.g. to resolve an external entity reference, indicated by an EntityReference node.
void reset | ( | ) |
All input sources are removed and the parser state is reset to parse a new document. The XmlResolver not removed and the reporting options are not changed.
void reset | ( | InputSource & | is | ) |
All previous input is removed and the parser is reset to parse a new document. This is essentially the same as calling reset() followed by addInput().
void setChunkSize | ( | std::size_t | n | ) |
If an XML element contains more character data than this limit, the content is reported as multiple Characters or CData nodes.