QXmlSerializer

Inherited by: QXmlFormatter

Synopsis

Functions

Detailed Description

The PySide.QtXmlPatterns.QXmlSerializer class is an implementation of PySide.QtXmlPatterns.QAbstractXmlReceiver for transforming XQuery output into unformatted XML.

PySide.QtXmlPatterns.QXmlSerializer translates an XQuery sequence , usually the output of an PySide.QtXmlPatterns.QXmlQuery , into 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 instance of this class with the query and myOutputDevice . 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 .

PySide.QtXmlPatterns.QXmlSerializer will:

  • Declare namespaces when needed,
  • Use appropriate escaping, when characters can’t be represented in the XML,
  • Handle line endings appropriately,
  • Report errors, when it can’t serialize the content, e.g., when asked to serialize an attribute that is a top-level node, or when more than one top-level element is encountered.

If an error occurs during serialization, result is undefined unless the serializer is driven through a call to QXmlQuery.evaluateTo() .

If the generated XML should be indented and formatted for reading, use PySide.QtXmlPatterns.QXmlFormatter .

class PySide.QtXmlPatterns.QXmlSerializer(query, outputDevice)
Parameters:

Constructs a serializer that uses the name pool and message handler in query , and writes the output to outputDevice .

outputDevice must be a valid, non-null device that is open in write mode, otherwise behavior is undefined.

outputDevice must not be opened with QIODevice.Text because it will cause the output to be incorrect. This class will ensure line endings are serialized as according with the XML specification. PySide.QtXmlPatterns.QXmlSerializer does not take ownership of outputDevice .

PySide.QtXmlPatterns.QXmlSerializer.State
PySide.QtXmlPatterns.QXmlSerializer.atDocumentRoot()
Return type:PySide.QtCore.bool
PySide.QtXmlPatterns.QXmlSerializer.codec()
Return type:PySide.QtCore.QTextCodec

Returns the codec being used by the serializer for encoding its XML output.

PySide.QtXmlPatterns.QXmlSerializer.isBindingInScope(nb)
Parameters:nbPySide.QtXmlPatterns.QXmlName
Return type:PySide.QtCore.bool
PySide.QtXmlPatterns.QXmlSerializer.outputDevice()
Return type:PySide.QtCore.QIODevice

Returns a pointer to the output device. There is no corresponding function to set the output device, because the output device must be passed to the constructor. The serializer does not take ownership of its IO device.

PySide.QtXmlPatterns.QXmlSerializer.setCodec(codec)
Parameters:codecPySide.QtCore.QTextCodec

Sets the codec the serializer will use for encoding its XML output. The output codec is set to outputCodec . By default, the output codec is set to the one for UTF-8 . The serializer does not take ownership of the codec.

PySide.QtXmlPatterns.QXmlSerializer.startContent()
PySide.QtXmlPatterns.QXmlSerializer.write(name)
Parameters:namePySide.QtXmlPatterns.QXmlName
PySide.QtXmlPatterns.QXmlSerializer.write(chars)
Parameters:chars – str
PySide.QtXmlPatterns.QXmlSerializer.write(content)
Parameters:content – unicode
PySide.QtXmlPatterns.QXmlSerializer.writeEscaped(toEscape)
Parameters:toEscape – unicode
PySide.QtXmlPatterns.QXmlSerializer.writeEscapedAttribute(toEscape)
Parameters:toEscape – unicode