<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qxmlserializer.cpp --> <title>QXmlSerializer Class | Qt XML Patterns 5.12.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtxmlpatterns-index.html">Qt XML Patterns</a></td><td ><a href="qtxmlpatterns-module.html">C++ Classes</a></td><td >QXmlSerializer</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtxmlpatterns-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QXmlSerializer Class</h1> <!-- $$$QXmlSerializer-brief --> <p>The <a href="qxmlserializer.html">QXmlSerializer</a> class is an implementation of QAbstractXmlReceiver for transforming <a href="xmlprocessing.html">XQuery</a> output into unformatted XML. <a href="#details">More...</a></p> <!-- @@@QXmlSerializer --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QXmlSerializer></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += xmlpatterns</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 4.4</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> QAbstractXmlReceiver</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherited By:</td><td class="memItemRight bottomAlign"> <p><a href="qxmlformatter.html">QXmlFormatter</a></p> </td></tr></table></div><ul> <li><a href="qxmlserializer-members.html">List of all members, including inherited members</a></li> </ul> <p><b>Note:</b> All functions in this class are reentrant.</p> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#QXmlSerializer">QXmlSerializer</a></b>(const QXmlQuery &<i>query</i>, QIODevice *<i>outputDevice</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#codec">codec</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QIODevice *</td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#outputDevice">outputDevice</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#setCodec">setCodec</a></b>(const QTextCodec *<i>outputCodec</i>)</td></tr> </table></div> <a name="reimplemented-public-functions"></a> <h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#atomicValue">atomicValue</a></b>(const QVariant &<i>value</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#attribute">attribute</a></b>(const QXmlName &<i>name</i>, const QStringRef &<i>value</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#characters">characters</a></b>(const QStringRef &<i>value</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#comment">comment</a></b>(const QString &<i>value</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#endDocument">endDocument</a></b>() override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#endElement">endElement</a></b>() override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#endOfSequence">endOfSequence</a></b>() override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#namespaceBinding">namespaceBinding</a></b>(const QXmlName &<i>nb</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#processingInstruction">processingInstruction</a></b>(const QXmlName &<i>name</i>, const QString &<i>value</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#startDocument">startDocument</a></b>() override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#startElement">startElement</a></b>(const QXmlName &<i>name</i>) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qxmlserializer.html#startOfSequence">startOfSequence</a></b>() override</td></tr> </table></div> <a name="details"></a> <!-- $$$QXmlSerializer-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qxmlserializer.html">QXmlSerializer</a> class is an implementation of QAbstractXmlReceiver for transforming <a href="xmlprocessing.html">XQuery</a> output into unformatted XML.</p> <p><a href="qxmlserializer.html">QXmlSerializer</a> translates an <a href="qpatternist-qabstractxmlreceiver.html#xquery-sequence">XQuery sequence</a>, usually the output of an <a href="qxmlquery.html">QXmlQuery</a>, into XML. Consider the example:</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"><a href="qxmlserializer.html#QXmlSerializer">QXmlSerializer</a></span> serializer(query<span class="operator">,</span> myOutputDevice); query<span class="operator">.</span>evaluateTo(<span class="operator">&</span>serializer); </pre> <p>First it constructs a <a href="qxmlquery.html">query</a> that gets the first paragraph from document <code>index.html</code>. Then it constructs an instance of this class with the <a href="qxmlquery.html">query</a> and myOutputDevice. Finally, it <a href="qxmlquery.html#evaluateTo">evaluates</a> the <a href="qxmlquery.html">query</a>, 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.</p> <p><a href="qxmlserializer.html">QXmlSerializer</a> will:</p> <ul> <li>Declare namespaces when needed,</li> <li>Use appropriate escaping, when characters can't be represented in the XML,</li> <li>Handle line endings appropriately,</li> <li>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.</li> </ul> <p>If an error occurs during serialization, result is undefined unless the serializer is driven through a call to <a href="qxmlquery.html#evaluateTo">QXmlQuery::evaluateTo</a>().</p> <p>If the generated XML should be indented and formatted for reading, use <a href="qxmlformatter.html">QXmlFormatter</a>.</p> </div> <p><b>See also </b><a href="http://www.w3.org/TR/xslt-xquery-serialization/">XSLT 2.0 and XQuery 1.0 Serialization</a> and <a href="qxmlformatter.html">QXmlFormatter</a>.</p> <!-- @@@QXmlSerializer --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QXmlSerializer[overload1]$$$QXmlSerializerconstQXmlQuery&QIODevice* --> <h3 class="fn" id="QXmlSerializer"><a name="QXmlSerializer"></a>QXmlSerializer::<span class="name">QXmlSerializer</span>(const <span class="type"><a href="qxmlquery.html">QXmlQuery</a></span> &<i>query</i>, <span class="type">QIODevice</span> *<i>outputDevice</i>)</h3> <p>Constructs a serializer that uses the name pool and message handler in <i>query</i>, and writes the output to <i>outputDevice</i>.</p> <p><i>outputDevice</i> must be a valid, non-null device that is open in write mode, otherwise behavior is undefined.</p> <p><i>outputDevice</i> 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. <a href="qxmlserializer.html">QXmlSerializer</a> does not take ownership of <i>outputDevice</i>.</p> <!-- @@@QXmlSerializer --> <!-- $$$atomicValue[overload1]$$$atomicValueconstQVariant& --> <h3 class="fn" id="atomicValue"><a name="atomicValue"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">atomicValue</span>(const <span class="type">QVariant</span> &<i>value</i>)</h3> <!-- @@@atomicValue --> <!-- $$$attribute[overload1]$$$attributeconstQXmlName&constQStringRef& --> <h3 class="fn" id="attribute"><a name="attribute"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">attribute</span>(const <span class="type"><a href="qxmlname.html">QXmlName</a></span> &<i>name</i>, const <span class="type">QStringRef</span> &<i>value</i>)</h3> <!-- @@@attribute --> <!-- $$$characters[overload1]$$$charactersconstQStringRef& --> <h3 class="fn" id="characters"><a name="characters"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">characters</span>(const <span class="type">QStringRef</span> &<i>value</i>)</h3> <!-- @@@characters --> <!-- $$$codec[overload1]$$$codec --> <h3 class="fn" id="codec"><a name="codec"></a>const <span class="type">QTextCodec</span> *QXmlSerializer::<span class="name">codec</span>() const</h3> <p>Returns the codec being used by the serializer for encoding its XML output.</p> <p><b>See also </b><a href="qxmlserializer.html#setCodec">setCodec</a>().</p> <!-- @@@codec --> <!-- $$$comment[overload1]$$$commentconstQString& --> <h3 class="fn" id="comment"><a name="comment"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">comment</span>(const <span class="type">QString</span> &<i>value</i>)</h3> <!-- @@@comment --> <!-- $$$endDocument[overload1]$$$endDocument --> <h3 class="fn" id="endDocument"><a name="endDocument"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">endDocument</span>()</h3> <!-- @@@endDocument --> <!-- $$$endElement[overload1]$$$endElement --> <h3 class="fn" id="endElement"><a name="endElement"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">endElement</span>()</h3> <!-- @@@endElement --> <!-- $$$endOfSequence[overload1]$$$endOfSequence --> <h3 class="fn" id="endOfSequence"><a name="endOfSequence"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">endOfSequence</span>()</h3> <!-- @@@endOfSequence --> <!-- $$$namespaceBinding[overload1]$$$namespaceBindingconstQXmlName& --> <h3 class="fn" id="namespaceBinding"><a name="namespaceBinding"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">namespaceBinding</span>(const <span class="type"><a href="qxmlname.html">QXmlName</a></span> &<i>nb</i>)</h3> <!-- @@@namespaceBinding --> <!-- $$$outputDevice[overload1]$$$outputDevice --> <h3 class="fn" id="outputDevice"><a name="outputDevice"></a><span class="type">QIODevice</span> *QXmlSerializer::<span class="name">outputDevice</span>() const</h3> <p>Returns a pointer to the output device. There is no corresponding function to <i>set</i> the output device, because the output device must be passed to the constructor. The serializer does not take ownership of its IO device.</p> <!-- @@@outputDevice --> <!-- $$$processingInstruction[overload1]$$$processingInstructionconstQXmlName&constQString& --> <h3 class="fn" id="processingInstruction"><a name="processingInstruction"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">processingInstruction</span>(const <span class="type"><a href="qxmlname.html">QXmlName</a></span> &<i>name</i>, const <span class="type">QString</span> &<i>value</i>)</h3> <!-- @@@processingInstruction --> <!-- $$$setCodec[overload1]$$$setCodecconstQTextCodec* --> <h3 class="fn" id="setCodec"><a name="setCodec"></a><span class="type">void</span> QXmlSerializer::<span class="name">setCodec</span>(const <span class="type">QTextCodec</span> *<i>outputCodec</i>)</h3> <p>Sets the codec the serializer will use for encoding its XML output. The output codec is set to <i>outputCodec</i>. By default, the output codec is set to the one for <code>UTF-8</code>. The serializer does not take ownership of the codec.</p> <p><b>See also </b><a href="qxmlserializer.html#codec">codec</a>().</p> <!-- @@@setCodec --> <!-- $$$startDocument[overload1]$$$startDocument --> <h3 class="fn" id="startDocument"><a name="startDocument"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">startDocument</span>()</h3> <!-- @@@startDocument --> <!-- $$$startElement[overload1]$$$startElementconstQXmlName& --> <h3 class="fn" id="startElement"><a name="startElement"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">startElement</span>(const <span class="type"><a href="qxmlname.html">QXmlName</a></span> &<i>name</i>)</h3> <!-- @@@startElement --> <!-- $$$startOfSequence[overload1]$$$startOfSequence --> <h3 class="fn" id="startOfSequence"><a name="startOfSequence"></a><code>[override virtual] </code><span class="type">void</span> QXmlSerializer::<span class="name">startOfSequence</span>()</h3> <!-- @@@startOfSequence --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> 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. </p> </div> </body> </html>