QAbstractXmlReceiver Class Reference
[QtXmlPatterns module]
该QAbstractXmlReceiver类提供了一个回调接口,用于将一个输出QXmlQuery。More…
通过继承QXmlSerializer。
Methods
__init__ (self)
atomicValue (self, QVariant value)
attribute (self, QXmlName name, QStringRef value)
characters (self, QStringRef value)
comment (self, QString value)
endDocument (self)
endElement (self)
endOfSequence (self)
namespaceBinding (self, QXmlName name)
processingInstruction (self, QXmlName target, QString value)
startDocument (self)
startElement (self, QXmlName name)
startOfSequence (self)
Detailed Description
该QAbstractXmlReceiver类提供了一个回调接口,用于将一个输出QXmlQuery。
QAbstractXmlReceiver是提供一个回调接口的抽象基类,用于接收XQuery sequence,一个通常的输出QXmlQuery和转化的顺序为您选择,通常是XML的结构。考虑例子:
[QXmlQuery]($docs-qxmlquery.html) query;
query.setQuery("doc('index.html')/html/body/p[1]");
[QXmlSerializer]($docs-qxmlserializer.html) serializer(query, myOutputDevice);
query.evaluateTo(&serializer);
首先它构造一个query这会从文档的第一段index.html
。然后,它构造了一个XML serializer与query和myOutputDevice(请注意serializer是XML receiver,即QAbstractXmlReceiver的一个子类) 。最后,它evaluates该query,生产调用的有序序列serializer’s回调函数。回调的序列转换查询输出到XML ,并将其写入到myOutputDevice。
虽然该示例使用QXmlQuery产生回调到QAbstractXmlReceiver功能的序列,可以直接,只要你的电话的序列代表一个有效的调用回调函数XQuery sequence。
XQuery Sequences
一个XQuery sequence是零的有序集合,一个或多个items。每item或者是一个atomic value或node。一个atomic value是一个简单的数据值。
有6种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.
该sequence的nodes和atomic values遵循以下规则。需要注意的是Namespace Node指的是一种特殊的Attribute Node与名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.
该sequence的nodes和atomic values被发送到一个QAbstractXmlReceiver (QXmlSerializer在上面的例子)作为呼叫接收器的回调函数的序列。的回调函数序列的项目的映射如下。
- 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.
- 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.
对于一个完整的解释XQuery序列,请访问XQuery Data Model。
Method Documentation
QAbstractXmlReceiver.__init__ (self)
构造一个抽象的XML接收器。
QAbstractXmlReceiver.atomicValue (self, QVariant value)
这种方法是抽象的,应在任何子类中重新实现。
当一个原子值出现在这个回调函数被调用sequence。该value是一个简单的data value。它是保证valid。
QAbstractXmlReceiver.attribute (self, QXmlName name, QStringRef value)
这种方法是抽象的,应在任何子类中重新实现。
QAbstractXmlReceiver.characters (self, QStringRef value)
这种方法是抽象的,应在任何子类中重新实现。
当一个文本节点会出现在这个回调函数被调用sequence。该value包含的文本。相邻的文本节点可能不会出现在sequence,也就是说,这个回调不能说是连续两次。
QAbstractXmlReceiver.comment (self, QString value)
这种方法是抽象的,应在任何子类中重新实现。
当一个注释节点会出现在这个回调函数被调用sequence。该value是注释文本,其中不得包含字符串“ - ” 。
QAbstractXmlReceiver.endDocument (self)
这种方法是抽象的,应在任何子类中重新实现。
当一个文档节点的末尾会出现在这个回调函数被调用sequence。
QAbstractXmlReceiver.endElement (self)
这种方法是抽象的,应在任何子类中重新实现。
当一个元素节点的结尾会出现在这个回调函数被调用sequence。
QAbstractXmlReceiver.endOfSequence (self)
这种方法是抽象的,应在任何子类中重新实现。
此回调被调用一次只,右后sequence结束。
QAbstractXmlReceiver.namespaceBinding (self, QXmlName name)
这种方法是抽象的,应在任何子类中重新实现。
此回调被调用时,一个命名空间绑定在元素的范围。命名空间是由一个URI来定义。在QXmlName name,的值QXmlName.namespaceUri()是URI。价值QXmlName.prefix()是该URI被绑定到前缀。本地名称是微不足道的,可以是任意值。
QAbstractXmlReceiver.processingInstruction (self, QXmlName target, QString value)
这种方法是抽象的,应在任何子类中重新实现。
当一个处理指令出现在此回调被调用sequence。处理指令用于在XML文档中告诉应用程序读取文件执行某些操作。一个典型的例子是使用处理指令来告诉应用程序使用特定的XSLT样式表来处理文档。
<?xml-stylesheet type="test/xsl" href="formatter.xsl"?>
target是name的处理指令。其prefix和namespace URI必须都是空的。其local name是目标。在上面的例子中,域名是xml-stylesheet。
该value指定要采取的行动。注意,这个value不得包含字符串“ \u003e ” 。在上面的例子中,value is type=”test/xsl” href=”formatter.xsl。
一般情况下,应避免使用处理指令,因为他们没有意识到命名空间和在许多情况下被剥离出来呢。处理指令通常可以替换为一个自定义的命名空间的元素。
QAbstractXmlReceiver.startDocument (self)
这种方法是抽象的,应在任何子类中重新实现。
当一个文档节点出现在这个回调函数被调用sequence。
QAbstractXmlReceiver.startElement (self, QXmlName name)
这种方法是抽象的,应在任何子类中重新实现。
当一个新的元素节点出现在这个回调函数被调用sequence。name是有效name该节点的元素。
QAbstractXmlReceiver.startOfSequence (self)
这种方法是抽象的,应在任何子类中重新实现。
此回调被调用一次而已,正确的前sequence开始。