A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQXmlStreamWriter</id>
		<title>C++/Qt/QXmlStreamWriter - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQXmlStreamWriter"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QXmlStreamWriter&amp;action=history"/>
		<updated>2026-04-18T18:31:58Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QXmlStreamWriter&amp;diff=1198&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QXmlStreamWriter&amp;diff=1198&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QXmlStreamWriter&amp;diff=1199&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QXmlStreamWriter&amp;diff=1199&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:07Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Pretty print XML==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#include &amp;lt;QCoreApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QFile&amp;gt;&lt;br /&gt;
#include &amp;lt;QHash&amp;gt;&lt;br /&gt;
#include &amp;lt;QPair&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QTextStream&amp;gt;&lt;br /&gt;
#include &amp;lt;QXmlStreamReader&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
    This class exists for the sole purpose of creating a translation context.&lt;br /&gt;
 */&lt;br /&gt;
class PrettyPrint&lt;br /&gt;
{&lt;br /&gt;
    Q_DECLARE_TR_FUNCTIONS(PrettyPrint)&lt;br /&gt;
};&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    enum ExitCode&lt;br /&gt;
    {&lt;br /&gt;
        Success,&lt;br /&gt;
        ParseFailure,&lt;br /&gt;
        ArgumentError,&lt;br /&gt;
        WriteError,&lt;br /&gt;
        FileFailure&lt;br /&gt;
    };&lt;br /&gt;
    QCoreApplication app(argc, argv);&lt;br /&gt;
    QTextStream errorStream(stderr);&lt;br /&gt;
    if (argc != 2)&lt;br /&gt;
    {&lt;br /&gt;
        errorStream &amp;lt;&amp;lt; PrettyPrint::tr(&lt;br /&gt;
                       &amp;quot;Usage: prettyprint &amp;lt;path to XML file&amp;gt;\n&amp;quot;);&lt;br /&gt;
        return ArgumentError;&lt;br /&gt;
    }&lt;br /&gt;
    QString inputFilePath(QCoreApplication::arguments().at(1));&lt;br /&gt;
    QFile inputFile(inputFilePath);&lt;br /&gt;
    if (!QFile::exists(inputFilePath))&lt;br /&gt;
    {&lt;br /&gt;
        errorStream &amp;lt;&amp;lt; PrettyPrint::tr(&lt;br /&gt;
                       &amp;quot;File %1 does not exist.\n&amp;quot;).arg(inputFilePath);&lt;br /&gt;
        return FileFailure;&lt;br /&gt;
    } else if (!inputFile.open(QIODevice::ReadOnly)) {&lt;br /&gt;
        errorStream &amp;lt;&amp;lt; PrettyPrint::tr(&lt;br /&gt;
                       &amp;quot;Failed to open file %1.\n&amp;quot;).arg(inputFilePath);&lt;br /&gt;
        return FileFailure;&lt;br /&gt;
    }&lt;br /&gt;
    QFile outputFile;&lt;br /&gt;
    if (!outputFile.open(stdout, QIODevice::WriteOnly))&lt;br /&gt;
    {&lt;br /&gt;
        QTextStream(stderr) &amp;lt;&amp;lt; PrettyPrint::tr(&amp;quot;Failed to open stdout.&amp;quot;);&lt;br /&gt;
        return WriteError;&lt;br /&gt;
    }&lt;br /&gt;
    QXmlStreamReader reader(&amp;amp;inputFile);&lt;br /&gt;
    int indentation = 0;&lt;br /&gt;
    QHash&amp;lt;int,QPair&amp;lt;int, int&amp;gt; &amp;gt; indentationStack;&lt;br /&gt;
    while (!reader.atEnd())&lt;br /&gt;
    {&lt;br /&gt;
        reader.readNext();&lt;br /&gt;
        if (reader.isStartElement()) {&lt;br /&gt;
            indentationStack[indentation] = QPair&amp;lt;int,int&amp;gt;(&lt;br /&gt;
                reader.lineNumber(), reader.columnNumber());&lt;br /&gt;
            indentation += 1;&lt;br /&gt;
        } else if (reader.isEndElement()) {&lt;br /&gt;
            indentationStack.remove(indentation);&lt;br /&gt;
            indentation -= 1;&lt;br /&gt;
        }&lt;br /&gt;
        if (reader.error())&lt;br /&gt;
        {&lt;br /&gt;
            errorStream &amp;lt;&amp;lt; PrettyPrint::tr(&lt;br /&gt;
                           &amp;quot;Error: %1 in file %2 at line %3, column %4.\n&amp;quot;).arg(&lt;br /&gt;
                               reader.errorString(), inputFilePath,&lt;br /&gt;
                               QString::number(reader.lineNumber()),&lt;br /&gt;
                               QString::number(reader.columnNumber()));&lt;br /&gt;
            if (indentationStack.contains(indentation-1)) {&lt;br /&gt;
                int line = indentationStack[indentation-1].first;&lt;br /&gt;
                int column = indentationStack[indentation-1].second;&lt;br /&gt;
                errorStream &amp;lt;&amp;lt; PrettyPrint::tr(&lt;br /&gt;
                               &amp;quot;Opened at line %1, column %2.\n&amp;quot;).arg(&lt;br /&gt;
                                   QString::number(line),&lt;br /&gt;
                                   QString::number(column));&lt;br /&gt;
            }&lt;br /&gt;
            return ParseFailure;&lt;br /&gt;
        } else if (reader.isStartElement() &amp;amp;&amp;amp; !reader.name().isEmpty()) {&lt;br /&gt;
            outputFile.write(QByteArray().fill(&amp;quot; &amp;quot;, indentation));&lt;br /&gt;
            outputFile.write(reader.name().toString().toLocal8Bit());&lt;br /&gt;
            outputFile.write(QString(&amp;quot; line %1, column %2\n&amp;quot;).arg(&lt;br /&gt;
                reader.lineNumber()).arg(reader.columnNumber()).toLocal8Bit());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    return Success;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using QXmlStreamWriter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#include &amp;lt;QCoreApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QFile&amp;gt;&lt;br /&gt;
#include &amp;lt;QXmlStreamWriter&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QCoreApplication app(argc, argv);&lt;br /&gt;
    QFile output;&lt;br /&gt;
    output.open(stdout, QIODevice::WriteOnly);&lt;br /&gt;
//! [write output]&lt;br /&gt;
//! [start stream]&lt;br /&gt;
    QXmlStreamWriter stream(&amp;amp;output);&lt;br /&gt;
    stream.setAutoFormatting(true);&lt;br /&gt;
    stream.writeStartDocument();&lt;br /&gt;
//! [start stream]&lt;br /&gt;
    stream.writeDTD(&amp;quot;&amp;lt;!DOCTYPE xbel&amp;gt;&amp;quot;);&lt;br /&gt;
    stream.writeStartElement(&amp;quot;xbel&amp;quot;);&lt;br /&gt;
    stream.writeAttribute(&amp;quot;version&amp;quot;, &amp;quot;1.0&amp;quot;);&lt;br /&gt;
    stream.writeStartElement(&amp;quot;folder&amp;quot;);&lt;br /&gt;
    stream.writeAttribute(&amp;quot;folded&amp;quot;, &amp;quot;no&amp;quot;);&lt;br /&gt;
//! [write element]&lt;br /&gt;
    stream.writeStartElement(&amp;quot;bookmark&amp;quot;);&lt;br /&gt;
    stream.writeAttribute(&amp;quot;href&amp;quot;, &amp;quot;http://qt.nokia.com/&amp;quot;);&lt;br /&gt;
    stream.writeTextElement(&amp;quot;title&amp;quot;, &amp;quot;Qt Home&amp;quot;);&lt;br /&gt;
    stream.writeEndElement(); // bookmark&lt;br /&gt;
//! [write element]&lt;br /&gt;
    stream.writeEndElement(); // folder&lt;br /&gt;
    stream.writeEndElement(); // xbel&lt;br /&gt;
//! [finish stream]&lt;br /&gt;
    stream.writeEndDocument();&lt;br /&gt;
//! [finish stream]&lt;br /&gt;
//! [write output]&lt;br /&gt;
    output.close();&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>