继承者: QXmlSerializer , QXmlFormatter
PySide.QtXmlPatterns.QAbstractXmlReceiver class provides a callback interface for transforming the output of a PySide.QtXmlPatterns.QXmlQuery .
PySide.QtXmlPatterns.QAbstractXmlReceiver is an abstract base class that provides a callback interface for receiving an XQuery sequence , usually the output of an PySide.QtXmlPatterns.QXmlQuery , 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 document index.html . Then it constructs an XML serializer 采用 query and myOutputDevice (Note the serializer 是 XML receiver , ie a subclass of PySide.QtXmlPatterns.QAbstractXmlReceiver ). Finally, it evaluates the query , producing an ordered sequence of calls to the serializer's callback functions. The sequence of callbacks transforms the query output to XML and writes it to myOutputDevice .
Although the example uses PySide.QtXmlPatterns.QXmlQuery to produce the sequence of callbacks to functions in PySide.QtXmlPatterns.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 或 node . An atomic value is a simple data value.
There are six kinds of nodes .
sequence of nodes and atomic values obeys the following rules. Note that Namespace Node refers to a special Attribute Node with name xmlns .
sequence of nodes and atomic values is sent to an PySide.QtXmlPatterns.QAbstractXmlReceiver ( PySide.QtXmlPatterns.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.
For a complete explanation of XQuery sequences, visit XQuery Data Model.
Constructs an abstract xml receiver.
| 参数: | value – object |
|---|
This callback is called when an atomic value appears in the sequence 。 value is a simple data value . It is guaranteed to be valid .
| 参数: |
|
|---|
This callback is called when an attribute node appears in the sequence . name 是 attribute name 和 value string contains the attribute value.
| 参数: | value – PySide.QtCore.QStringRef |
|---|
This callback is called when a text node appears in the sequence 。 value contains the text. Adjacent text nodes may not occur in the sequence , i.e., this callback must not be called twice in a row.
| 参数: | value – unicode |
|---|
This callback is called when a comment node appears in the sequence 。 value is the comment text, which must not contain the string “–”.
This callback is called when the end of a document node appears in the sequence .
This callback is called when the end of an element node appears in the sequence .
This callback is called once only, right after the sequence ends.
| 参数: | name – PySide.QtXmlPatterns.QXmlName |
|---|
This callback is called when a namespace binding is in scope of an element. A namespace is defined by a URI. In the PySide.QtXmlPatterns.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.
| 参数: |
|
|---|
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.
<?xml-stylesheet type="test/xsl" href="formatter.xsl"?>
target 是 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 .
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.
| 参数: | node – PySide.QtXmlPatterns.QXmlNodeModelIndex |
|---|
This callback is called when a document node appears in the sequence .
| 参数: | name – PySide.QtXmlPatterns.QXmlName |
|---|
This callback is called when a new element node appears in the sequence . name is the valid name of the node element.
This callback is called once only, right before the sequence begins.
| 参数: | value – PySide.QtCore.QStringRef |
|---|
This function may be called instead of PySide.QtXmlPatterns.QAbstractXmlReceiver.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 PySide.QtXmlPatterns.QAbstractXmlReceiver.whitespaceOnly() is called for text nodes containing whitespace only. PySide.QtXmlPatterns.QAbstractXmlReceiver.characters() may be called just as well. This is why the default implementation for PySide.QtXmlPatterns.QAbstractXmlReceiver.whitespaceOnly() calls PySide.QtXmlPatterns.QAbstractXmlReceiver.characters() .