Qt 4.8
|
The QAbstractXmlReceiver class provides a callback interface for transforming the output of a QXmlQuery. More...
#include <qabstractxmlreceiver.h>
Public Functions | |
virtual void | atomicValue (const QVariant &value)=0 |
This callback is called when an atomic value appears in the XQuery Sequence. More... | |
virtual void | attribute (const QXmlName &name, const QStringRef &value)=0 |
This callback is called when an attribute node appears in the XQuery Sequence. More... | |
virtual void | characters (const QStringRef &value)=0 |
This callback is called when a text node appears in the XQuery Sequence. More... | |
virtual void | comment (const QString &value)=0 |
This callback is called when a comment node appears in the XQuery Sequence. More... | |
virtual void | endDocument ()=0 |
This callback is called when the end of a document node appears in the XQuery Sequence. More... | |
virtual void | endElement ()=0 |
This callback is called when the end of an element node appears in the XQuery Sequence. More... | |
virtual void | endOfSequence ()=0 |
This callback is called once only, right after the XQuery Sequence ends. More... | |
virtual void | item (const QPatternist::Item &item) |
virtual void | namespaceBinding (const QXmlName &name)=0 |
This callback is called when a namespace binding is in scope of an element. More... | |
virtual void | processingInstruction (const QXmlName &target, const QString &value)=0 |
This callback is called when a processing instruction appears in the XQuery Sequence. More... | |
QAbstractXmlReceiver () | |
Constructs an abstract xml receiver. More... | |
virtual void | startDocument ()=0 |
This callback is called when a document node appears in the XQuery Sequence. More... | |
virtual void | startElement (const QXmlName &name)=0 |
This callback is called when a new element node appears in the XQuery Sequence. More... | |
virtual void | startOfSequence ()=0 |
This callback is called once only, right before the XQuery Sequence begins. More... | |
virtual void | whitespaceOnly (const QStringRef &value) |
This function may be called instead of characters() if, and only if, value consists only of whitespace. More... | |
virtual | ~QAbstractXmlReceiver () |
Destroys the xml receiver. More... | |
Protected Functions | |
QAbstractXmlReceiver (QAbstractXmlReceiverPrivate *d) | |
void | sendAsNode (const QPatternist::Item &outputItem) |
Treats outputItem as a node and calls the appropriate function, e. More... | |
Protected Variables | |
QScopedPointer< QAbstractXmlReceiverPrivate > | d_ptr |
Private Functions | |
template<const QXmlNodeModelIndex::Axis axis> | |
void | sendFromAxis (const QXmlNodeModelIndex &node) |
The QAbstractXmlReceiver class provides a callback interface for transforming the output of a QXmlQuery.
QAbstractXmlReceiver is an abstract base class that provides a callback interface for receiving an XQuery Sequence, usually the output of an QXmlQuery, and transforming that sequence into a structure of your choosing, usually XML. Consider the example:
First it constructs a QXmlQuery {query} that gets the first paragraph from document index.html
. Then it constructs an QXmlSerializer {XML serializer} with the QXmlQuery {query} and QIODevice {myOutputDevice} (Note the QXmlSerializer {serializer} is an {XML receiver}, ie a subclass of QAbstractXmlReceiver). Finally, it QXmlQuery::evaluateTo() {evaluates} the QXmlQuery {query}, producing an ordered sequence of calls to the QXmlSerializer {serializer's} callback functions. The sequence of callbacks transforms the query output to XML and writes it to QIODevice {myOutputDevice}.
Although the example uses QXmlQuery to produce the sequence of callbacks to functions in QAbstractXmlReceiver, you can call the callback functions directly as long as your sequence of calls represents a valid XQuery Sequence.
An XQuery sequence is an ordered collection of zero, one, or many items. Each item is either an {atomic value} or a {node}. An {atomic value} is a simple data value.
There are six kinds of nodes.
An {Attribute Node} represents an XML attribute.
A {Processing Instruction Node} represents an XML processing instruction, which is used in an XML document to tell the application reading the document to perform some action. A typical example is to use a processing instruction to tell the application to use a particular XSLT stylesheet to display the document.
And a {Comment node} represents an XML comment.
The sequence of nodes and {atomic values} obeys the following rules. Note that {Namespace Node} refers to a special {Attribute Node} with name {xmlns}.
Each node appears in the sequence before its children and their descendants appear.
A node's descendants appear in the sequence before any of its siblings appear.
A {Document Node} represents an entire document. Zero or more {Document Nodes} can appear in a sequence, but they can only be top level items (i.e., a {Document Node} can't be a child of another node.
{Namespace Nodes} immediately follow the {Element Node} with which they are associated.
{Attribute Nodes} immediately follow the {Namespace Nodes} of the element with which they are associated, or...
If there are no {Namespace Nodes} following an element, then the {Attribute Nodes} immediately follow the element.
An {atomic value} can only appear as a top level item, i.e., it can't appear as a child of a node.
{Processing Instruction Nodes} do not have children, and their parent is either a {Document Node} or an {Element Node}.
{Comment Nodes} do not have children, and their parent is either a {Document Node} or an {Element Node}.
The sequence of nodes and {atomic values} is sent to an QAbstractXmlReceiver (QXmlSerializer in the example above) as a sequence of calls to the receiver's callback functions. The mapping of callback functions to sequence items is as follows.
startDocument() and endDocument() are called for each {Document Node} in the sequence. endDocument() is not called until all the {Document Node's} children have appeared in the sequence.
startElement() and endElement() are called for each {Element Node}. endElement() is not called until all the {Element Node's} children have appeared in the sequence.
attribute() is called for each {Attribute Node}.
characters() is called for each {Text Node}.
processingInstruction() is called for each {Processing Instruction Node}.
namespaceBinding() is called for each {Namespace Node}.
atomicValue() is called for each {atomic value}.
For a complete explanation of XQuery sequences, visit http://www.w3.org/TR/xpath-datamodel/ {XQuery Data Model}.
Definition at line 63 of file qabstractxmlreceiver.h.
QAbstractXmlReceiver::QAbstractXmlReceiver | ( | ) |
Constructs an abstract xml receiver.
Definition at line 220 of file qabstractxmlreceiver.cpp.
|
virtual |
|
protected |
Definition at line 212 of file qabstractxmlreceiver.cpp.
|
pure virtual |
This callback is called when an atomic value appears in the XQuery Sequence.
The value is a simple QVariant {data value}. It is guaranteed to be QVariant::isValid() {valid}.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by item().
|
pure virtual |
This callback is called when an attribute node appears in the XQuery Sequence.
name is the QXmlName {attribute name} and the value string contains the attribute value.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
pure virtual |
This callback is called when a text node appears in the XQuery Sequence.
The value contains the text. Adjacent text nodes may not occur in the XQuery Sequence, i.e., this callback must not be called twice in a row.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode(), and whitespaceOnly().
|
pure virtual |
This callback is called when a comment node appears in the XQuery Sequence.
The value is the comment text, which must not contain the string "--".
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
pure virtual |
This callback is called when the end of a document node appears in the XQuery Sequence.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
pure virtual |
This callback is called when the end of an element node appears in the XQuery Sequence.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
pure virtual |
This callback is called once only, right after the XQuery Sequence ends.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by QXmlQuery::evaluateTo().
|
virtual |
Reimplemented in QXmlSerializer, and QXmlFormatter.
Definition at line 488 of file qabstractxmlreceiver.cpp.
|
pure virtual |
This callback is called when a namespace binding is in scope of an element.
A namespace is defined by a URI. In the QXmlName name, the value of QXmlName::namespaceUri() is that URI. The value of QXmlName::prefix() is the prefix that the URI is bound to. The local name is insignificant and can be an arbitrary value.
Implemented in QXmlSerializer.
|
pure virtual |
This callback is called when a processing instruction appears in the XQuery Sequence.
A processing instruction is used in an XML document to tell the application reading the document to perform some action. A typical example is to use a processing instruction to tell the application to use a particular XSLT stylesheet to process the document.
target is the QXmlName {name} of the processing instruction. Its prefix and {namespace URI} must both be empty. Its {local name} is the target. In the above example, the name is {xml-stylesheet}.
The value specifies the action to be taken. Note that the value must not contain the string "?>". In the above example, the value is type="test/xsl" href="formatter.xsl.
Generally, use of processing instructions should be avoided, because they are not namespace aware and in many contexts are stripped out anyway. Processing instructions can often be replaced with elements from a custom namespace.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
protected |
Treats outputItem as a node and calls the appropriate function, e.
g., attribute() or comment(), depending on its QXmlNodeModelIndex::NodeKind.
This is a helper function that subclasses can use to multiplex Nodes received via item().
Definition at line 397 of file qabstractxmlreceiver.cpp.
Referenced by item(), QXmlSerializer::item(), and sendFromAxis().
|
private |
Definition at line 196 of file qabstractxmlreceiver.cpp.
|
pure virtual |
This callback is called when a document node appears in the XQuery Sequence.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
pure virtual |
This callback is called when a new element node appears in the XQuery Sequence.
name is the valid QXmlName {name} of the node element.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by sendAsNode().
|
pure virtual |
This callback is called once only, right before the XQuery Sequence begins.
Implemented in QXmlSerializer, and QXmlFormatter.
Referenced by QXmlQuery::evaluateTo().
|
virtual |
This function may be called instead of characters() if, and only if, value consists only of whitespace.
The caller gurantees that value is not empty.
Whitespace refers to a sequence of characters that are either spaces, tabs, or newlines, in any order. In other words, not all the Unicode whitespace category is considered whitespace here.
However, there is no guarantee or requirement that whitespaceOnly() is called for text nodes containing whitespace only. characters() may be called just as well. This is why the default implementation for whitespaceOnly() calls characters().
Definition at line 477 of file qabstractxmlreceiver.cpp.
|
protected |
Definition at line 94 of file qabstractxmlreceiver.h.