QAbstractXmlReceiver Class Reference

[QtXmlPatterns module]

该QAbstractXmlReceiver类提供了一个回调接口,用于将一个输出QXmlQueryMore…

通过继承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的结构。考虑例子:

  1. [QXmlQuery]($docs-qxmlquery.html) query;
  2. query.setQuery("doc('index.html')/html/body/p[1]");
  3. [QXmlSerializer]($docs-qxmlserializer.html) serializer(query, myOutputDevice);
  4. query.evaluateTo(&serializer);

首先它构造一个query这会从文档的第一段index.html。然后,它构造了一个XML serializerquerymyOutputDevice(请注意serializerXML receiver,即QAbstractXmlReceiver的一个子类) 。最后,它evaluatesquery,生产调用的有序序列serializer’s回调函数。回调的序列转换查询输出到XML ,并将其写入到myOutputDevice

虽然该示例使用QXmlQuery产生回调到QAbstractXmlReceiver功能的序列,可以直接,只要你的电话的序列代表一个有效的调用回调函数XQuery sequence

XQuery Sequences

一个XQuery sequence是零的有序集合,一个或多个items。每item或者是一个atomic valuenode。一个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.

sequencenodesatomic 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.

sequencenodesatomic values被发送到一个QAbstractXmlReceiver (QXmlSerializer在上面的例子)作为呼叫接收器的回调函数的序列。的回调函数序列的项目的映射如下。

对于一个完整的解释XQuery序列,请访问XQuery Data Model


Method Documentation

  1. QAbstractXmlReceiver.__init__ (self)

构造一个抽象的XML接收器。

  1. QAbstractXmlReceiver.atomicValue (self, QVariant value)

这种方法是抽象的,应在任何子类中重新实现。

当一个原子值出现在这个回调函数被调用sequence。该value是一个简单的data value。它是保证valid

  1. QAbstractXmlReceiver.attribute (self, QXmlName name, QStringRef value)

这种方法是抽象的,应在任何子类中重新实现。

  1. QAbstractXmlReceiver.characters (self, QStringRef value)

这种方法是抽象的,应在任何子类中重新实现。

当一个文本节点会出现在这个回调函数被调用sequence。该value包含的文本。相邻的文本节点可能不会出现在sequence,也就是说,这个回调不能说是连续两次。

  1. QAbstractXmlReceiver.comment (self, QString value)

这种方法是抽象的,应在任何子类中重新实现。

当一个注释节点会出现在这个回调函数被调用sequence。该value是注释文本,其中不得包含字符串“ - ” 。

  1. QAbstractXmlReceiver.endDocument (self)

这种方法是抽象的,应在任何子类中重新实现。

当一个文档节点的末尾会出现在这个回调函数被调用sequence

  1. QAbstractXmlReceiver.endElement (self)

这种方法是抽象的,应在任何子类中重新实现。

当一个元素节点的结尾会出现在这个回调函数被调用sequence

  1. QAbstractXmlReceiver.endOfSequence (self)

这种方法是抽象的,应在任何子类中重新实现。

此回调被调用一次只,右后sequence结束。

  1. QAbstractXmlReceiver.namespaceBinding (self, QXmlName name)

这种方法是抽象的,应在任何子类中重新实现。

此回调被调用时,一个命名空间绑定在元素的范围。命名空间是由一个URI来定义。在QXmlName name,的值QXmlName.namespaceUri()是URI。价值QXmlName.prefix()是该URI被绑定到前缀。本地名称是微不足道的,可以是任意值。

  1. QAbstractXmlReceiver.processingInstruction (self, QXmlName target, QString value)

这种方法是抽象的,应在任何子类中重新实现。

当一个处理指令出现在此回调被调用sequence。处理指令用于在XML文档中告诉应用程序读取文件执行某些操作。一个典型的例子是使用处理指令来告诉应用程序使用特定的XSLT样式表来处理文档。

  1. <?xml-stylesheet type="test/xsl" href="formatter.xsl"?>

targetname的处理指令。其prefixnamespace URI必须都是空的。其local name是目标。在上面的例子中,域名是xml-stylesheet

value指定要采取的行动。注意,这个value不得包含字符串“ \u003e ” 。在上面的例子中,value is type=”test/xsl” href=”formatter.xsl

一般情况下,应避免使用处理指令,因为他们没有意识到命名空间和在许多情况下被剥离出来呢。处理指令通常可以替换为一个自定义的命名空间的元素。

  1. QAbstractXmlReceiver.startDocument (self)

这种方法是抽象的,应在任何子类中重新实现。

当一个文档节点出现在这个回调函数被调用sequence

  1. QAbstractXmlReceiver.startElement (self, QXmlName name)

这种方法是抽象的,应在任何子类中重新实现。

当一个新的元素节点出现在这个回调函数被调用sequencename是有效name该节点的元素。

  1. QAbstractXmlReceiver.startOfSequence (self)

这种方法是抽象的,应在任何子类中重新实现。

此回调被调用一次而已,正确的前sequence开始。