QXmlFormatter¶
The
QXmlFormatterclass is an implementation ofQXmlSerializerfor transforming XQuery output into formatted XML. More…

Synopsis¶
Functions¶
def
indentationDepth()def
setIndentationDepth(depth)
Detailed Description¶
QXmlFormatteris a subclass ofQXmlSerializerthat formats the XML output to make it easier for humans to read.
QXmlSerializeroutputs XML without adding unnecessary whitespace. In particular, it does not add newlines and indentation. To make the XML output easier to read,QXmlFormatteradds newlines and indentation by adding, removing, and modifyingsequence nodesthat only consist of whitespace. It also modifies whitespace in other places where it is not significant; e.g., between attributes and in the document prologue.For example, where the base class
QXmlSerializerwould output this:<Code snippet "/data/snapshot-qt5full-5.15/qt5/qtbase/patternist/notIndented.xml" not found>
QXmlFormatteroutputs this:<Code snippet "/data/snapshot-qt5full-5.15/qt5/qtbase/patternist/indented.xml" not found>If you just want to serialize your XML in a human-readable format, use
QXmlFormatteras it is. The default indentation level is 4 spaces, but you can set your own indentation valuesetIndentationDepth().The newlines and indentation added by
QXmlFormatterare suitable for common formats, such as XHTML, SVG, or Docbook, where whitespace is not significant. However, if your XML will be used as input where whitespace is significant, then you must write your own subclass ofQXmlSerializerorQAbstractXmlReceiver.Note that using
QXmlFormatterinstead ofQXmlSerializerwill increase computational overhead and document storage size due to the insertion of whitespace.Note also that the indentation style used by
QXmlFormatterremains loosely defined and may change in future versions of Qt. If a specific indentation style is required then either use the base classQXmlSerializerdirectly, or write your own subclass ofQXmlSerializerorQAbstractXmlReceiver. Alternatively, you can subclassQXmlFormatterand reimplement the callbacks there.QXmlQuery query; query.setQuery("doc('index.html')/html/body/p[1]"); QXmlFormatter formatter(query, myOutputDevice); formatter.setIndentationDepth(2); query.evaluateTo(&formatter);
- class PySide2.QtXmlPatterns.QXmlFormatter(query, outputDevice)¶
- param query:
- param outputDevice:
Constructs a formatter that uses the name pool and message handler in
query, and writes the result tooutputDeviceas formatted XML.outputDeviceis passed directly toQXmlSerializer‘s constructor.See also
- PySide2.QtXmlPatterns.QXmlFormatter.indentationDepth()¶
- Return type:
int
Returns the number of spaces
QXmlFormatterwill output for each indentation level. The default is four.See also
- PySide2.QtXmlPatterns.QXmlFormatter.setIndentationDepth(depth)¶
- Parameters:
depth – int
Sets
depthto be the number of spacesQXmlFormatterwill output for level of indentation. The default is four.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.