QAbstractXmlReceiver¶
The
QAbstractXmlReceiver
class provides a callback interface for transforming the output of aQXmlQuery
. More…
Inherited by: QXmlFormatter, QXmlSerializer
Detailed Description¶
QAbstractXmlReceiver
is an abstract base class that provides a callback interface for receiving anXQuery sequence
, usually the output of anQXmlQuery
, and transforming that sequence into a structure of your choosing, usually XML. Consider the example:QXmlQuery query; query.setQuery("doc('index.html')/html/body/p[1]"); QXmlSerializer serializer(query, myOutputDevice); query.evaluateTo(&serializer);First it constructs a
query
that gets the first paragraph from documentindex.html
. Then it constructs anXML serializer
with thequery
andmyOutputDevice
(Note theserializer
is an XML receiver , ie a subclass ofQAbstractXmlReceiver
). Finally, itevaluates
thequery
, producing an ordered sequence of calls to theserializer's
callback functions. The sequence of callbacks transforms the query output to XML and writes it tomyOutputDevice
.Although the example uses
QXmlQuery
to produce the sequence of callbacks to functions inQAbstractXmlReceiver
, you can call the callback functions directly as long as your sequence of calls represents a validXQuery sequence
.
XQuery Sequences¶
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 Element Node represents an XML element.
An Attribute Node represents an XML attribute.
A Document Node represents an entire XML document.
A Text Node represents character data (element content).
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()
andendDocument()
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()
andendElement()
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.
comment()
is called for each Comment 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 XQuery Data Model .
- class PySide2.QtXmlPatterns.QAbstractXmlReceiver¶
Constructs an abstract xml receiver.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.atomicValue(value)¶
- Parameters:
value – object
This callback is called when an atomic value appears in the
sequence
. Thevalue
is a simpledata value
. It is guaranteed to bevalid
.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.attribute(name, value)¶
- Parameters:
value –
QStringRef
This callback is called when an attribute node appears in the
sequence
.name
is theattribute name
and thevalue
string contains the attribute value.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.characters(value)¶
- Parameters:
value –
QStringRef
This callback is called when a text node appears in the
sequence
. Thevalue
contains the text. Adjacent text nodes may not occur in thesequence
, i.e., this callback must not be called twice in a row.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.comment(value)¶
- Parameters:
value – str
This callback is called when a comment node appears in the
sequence
. Thevalue
is the comment text, which must not contain the string “–“.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.endDocument()¶
This callback is called when the end of a document node appears in the
sequence
.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.endElement()¶
This callback is called when the end of an element node appears in the
sequence
.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.endOfSequence()¶
This callback is called once only, right after the
sequence
ends.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.namespaceBinding(name)¶
- Parameters:
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 ofnamespaceUri()
is that URI. The value ofprefix
() is the prefix that the URI is bound to. The local name is insignificant and can be an arbitrary value.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.processingInstruction(target, value)¶
- Parameters:
target –
PySide2.QtXmlPatterns.QXmlName
value – str
This callback is called when a processing instruction appears in the
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.<Code snippet "/data/snapshot-qt5full-5.15/qt5/qtbase/patternist/xmlStylesheet.xq" not found>
target
is thename
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 thevalue
must not contain the string “?>”. In the above example, thevalue
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.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.startDocument()¶
This callback is called when a document node appears in the
sequence
.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.startElement(name)¶
- Parameters:
This callback is called when a new element node appears in the
sequence
.name
is the validname
of the node element.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.startOfSequence()¶
This callback is called once only, right before the
sequence
begins.
- PySide2.QtXmlPatterns.QAbstractXmlReceiver.whitespaceOnly(value)¶
- Parameters:
value –
QStringRef
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 is called for text nodes containing whitespace only.
characters()
may be called just as well. This is why the default implementation for callscharacters()
.See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.