<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QXmlFormatter Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QXmlFormatter Class Reference<br /><sup><sup>[<a href="qtxmlpatterns.html">QtXmlPatterns</a> module]</sup></sup></h1><p>The QXmlFormatter class is an implementation of <a href="qxmlserializer.html">QXmlSerializer</a> for transforming <a href="xmlprocessing.html">XQuery</a> output into formatted XML. <a href="#details">More...</a></p> <p>Inherits <a href="qxmlserializer.html">QXmlSerializer</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qxmlformatter.html#QXmlFormatter">__init__</a></b> (<i>self</i>, QXmlQuery <i>query</i>, QIODevice <i>outputDevice</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#atomicValue">atomicValue</a></b> (<i>self</i>, QVariant <i>value</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#attribute">attribute</a></b> (<i>self</i>, QXmlName <i>name</i>, QStringRef <i>value</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#characters">characters</a></b> (<i>self</i>, QStringRef <i>value</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#comment">comment</a></b> (<i>self</i>, QString <i>value</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#endDocument">endDocument</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#endElement">endElement</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#endOfSequence">endOfSequence</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qxmlformatter.html#indentationDepth">indentationDepth</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#processingInstruction">processingInstruction</a></b> (<i>self</i>, QXmlName <i>name</i>, QString <i>value</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#setIndentationDepth">setIndentationDepth</a></b> (<i>self</i>, int <i>depth</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#startDocument">startDocument</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#startElement">startElement</a></b> (<i>self</i>, QXmlName <i>name</i>)</li><li><div class="fn" /><b><a href="qxmlformatter.html#startOfSequence">startOfSequence</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QXmlFormatter class is an implementation of <a href="qxmlserializer.html">QXmlSerializer</a> for transforming <a href="xmlprocessing.html">XQuery</a> output into formatted XML.</p> <p>QXmlFormatter is a subclass of <a href="qxmlserializer.html">QXmlSerializer</a> that formats the XML output to make it easier for humans to read.</p> <p><a href="qxmlserializer.html">QXmlSerializer</a> outputs XML without adding unnecessary whitespace. In particular, it does not add <i>newlines</i> and indentation. To make the XML output easier to read, QXmlFormatter adds <i>newlines</i> and indentation by adding, removing, and modifying <a href="qabstractxmlreceiver.html#xquery-sequence">sequence nodes</a> that 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.</p> <p>For example, where the base class <a href="qxmlserializer.html">QXmlSerializer</a> would output this:</p> <pre class="cpp"> <a><b/><c/><p>Some Text</p></a> </pre> <p>QXmlFormatter outputs this:</p> <pre class="cpp"> <a> <b/> <c/> <p>Some Text</p> </a> </pre> <p>If you just want to serialize your XML in a human-readable format, use QXmlFormatter as it is. The default indentation level is 4 spaces, but you can set your own indentation value <a href="qxmlformatter.html#setIndentationDepth">setIndentationDepth</a>().</p> <p>The <i>newlines</i> and indentation added by QXmlFormatter are 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 of <a href="qxmlserializer.html">QXmlSerializer</a> or <a href="qabstractxmlreceiver.html">QAbstractXmlReceiver</a>.</p> <p>Note that using QXmlFormatter instead of <a href="qxmlserializer.html">QXmlSerializer</a> will increase computational overhead and document storage size due to the insertion of whitespace.</p> <p>Note also that the indentation style used by QXmlFormatter remains loosely defined and may change in future versions of Qt. If a specific indentation style is required then either use the base class <a href="qxmlserializer.html">QXmlSerializer</a> directly, or write your own subclass of <a href="qxmlserializer.html">QXmlSerializer</a> or <a href="qabstractxmlreceiver.html">QAbstractXmlReceiver</a>. Alternatively, you can subclass QXmlFormatter and reimplement the callbacks there.</p> <pre class="cpp"> <span class="type"><a href="qxmlquery.html">QXmlQuery</a></span> query; query<span class="operator">.</span>setQuery(<span class="string">"doc('index.html')/html/body/p[1]"</span>); <span class="type">QXmlFormatter</span> formatter(query<span class="operator">,</span> myOutputDevice); formatter<span class="operator">.</span><a href="qxmlformatter.html#setIndentationDepth">setIndentationDepth</a>(<span class="number">2</span>); query<span class="operator">.</span>evaluateTo(<span class="operator">&</span>formatter); </pre><hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QXmlFormatter" />QXmlFormatter.__init__ (<i>self</i>, <a href="qxmlquery.html">QXmlQuery</a> <i>query</i>, <a href="qiodevice.html">QIODevice</a> <i>outputDevice</i>)</h3><p>Constructs a formatter that uses the name pool and message handler in <i>query</i>, and writes the result to <i>outputDevice</i> as formatted XML.</p> <p><i>outputDevice</i> is passed directly to <a href="qxmlserializer.html">QXmlSerializer</a>'s constructor.</p> <p><b>See also</b> <a href="qxmlserializer.html">QXmlSerializer</a>.</p> <h3 class="fn"><a name="atomicValue" />QXmlFormatter.atomicValue (<i>self</i>, QVariant <i>value</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#atomicValue">QAbstractXmlReceiver.atomicValue</a>().</p> <h3 class="fn"><a name="attribute" />QXmlFormatter.attribute (<i>self</i>, <a href="qxmlname.html">QXmlName</a> <i>name</i>, QStringRef <i>value</i>)</h3><h3 class="fn"><a name="characters" />QXmlFormatter.characters (<i>self</i>, QStringRef <i>value</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#characters">QAbstractXmlReceiver.characters</a>().</p> <h3 class="fn"><a name="comment" />QXmlFormatter.comment (<i>self</i>, QString <i>value</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#comment">QAbstractXmlReceiver.comment</a>().</p> <h3 class="fn"><a name="endDocument" />QXmlFormatter.endDocument (<i>self</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#endDocument">QAbstractXmlReceiver.endDocument</a>().</p> <h3 class="fn"><a name="endElement" />QXmlFormatter.endElement (<i>self</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#endElement">QAbstractXmlReceiver.endElement</a>().</p> <h3 class="fn"><a name="endOfSequence" />QXmlFormatter.endOfSequence (<i>self</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#endOfSequence">QAbstractXmlReceiver.endOfSequence</a>().</p> <h3 class="fn"><a name="indentationDepth" />int QXmlFormatter.indentationDepth (<i>self</i>)</h3><p>Returns the number of spaces <a href="qxmlformatter.html">QXmlFormatter</a> will output for each indentation level. The default is four.</p> <p><b>See also</b> <a href="qxmlformatter.html#setIndentationDepth">setIndentationDepth</a>().</p> <h3 class="fn"><a name="processingInstruction" />QXmlFormatter.processingInstruction (<i>self</i>, <a href="qxmlname.html">QXmlName</a> <i>name</i>, QString <i>value</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#processingInstruction">QAbstractXmlReceiver.processingInstruction</a>().</p> <h3 class="fn"><a name="setIndentationDepth" />QXmlFormatter.setIndentationDepth (<i>self</i>, int <i>depth</i>)</h3><p>Sets <i>depth</i> to be the number of spaces <a href="qxmlformatter.html">QXmlFormatter</a> will output for level of indentation. The default is four.</p> <p><b>See also</b> <a href="qxmlformatter.html#indentationDepth">indentationDepth</a>().</p> <h3 class="fn"><a name="startDocument" />QXmlFormatter.startDocument (<i>self</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#startDocument">QAbstractXmlReceiver.startDocument</a>().</p> <h3 class="fn"><a name="startElement" />QXmlFormatter.startElement (<i>self</i>, <a href="qxmlname.html">QXmlName</a> <i>name</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#startElement">QAbstractXmlReceiver.startElement</a>().</p> <h3 class="fn"><a name="startOfSequence" />QXmlFormatter.startOfSequence (<i>self</i>)</h3><p>Reimplemented from <a href="qabstractxmlreceiver.html#startOfSequence">QAbstractXmlReceiver.startOfSequence</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>