Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QXmlFormatter Class

TheQXmlFormatter class is an implementation ofQXmlSerializer for transformingXQuery output into formatted XML.More...

Header:#include <QXmlFormatter>
Since: Qt 4.4
Inherits:QXmlSerializer

Note: All functions in this class arereentrant.

Public Functions

QXmlFormatter(const QXmlQuery & query, QIODevice * outputDevice)
intindentationDepth() const
voidsetIndentationDepth(int depth)

Reimplemented Public Functions

virtual voidatomicValue(const QVariant & value)
virtual voidattribute(const QXmlName & name, const QStringRef & value)
virtual voidcharacters(const QStringRef & value)
virtual voidcomment(const QString & value)
virtual voidendDocument()
virtual voidendElement()
virtual voidendOfSequence()
virtual voidprocessingInstruction(const QXmlName & name, const QString & value)
virtual voidstartDocument()
virtual voidstartElement(const QXmlName & name)
virtual voidstartOfSequence()

Detailed Description

TheQXmlFormatter class is an implementation ofQXmlSerializer for transformingXQuery output into formatted XML.

QXmlFormatter is a subclass ofQXmlSerializer that formats the XML output to make it easier for humans to read.

QXmlSerializer outputs XML without adding unnecessary whitespace. In particular, it does not addnewlines and indentation. To make the XML output easier to read,QXmlFormatter addsnewlines and indentation by adding, removing, and modifyingsequence nodes 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.

For example, where the base classQXmlSerializer would output this:

<a><b/><c/><p>Some Text</p></a>

QXmlFormatter outputs this:

<a>   <b/>   <c/>   <p>Some Text</p></a>

If you just want to serialize your XML in a human-readable format, useQXmlFormatter as it is. The default indentation level is 4 spaces, but you can set your own indentation valuesetIndentationDepth().

Thenewlines and indentation added byQXmlFormatter 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 ofQXmlSerializer orQAbstractXmlReceiver.

Note that usingQXmlFormatter instead ofQXmlSerializer will increase computational overhead and document storage size due to the insertion of whitespace.

Note also that the indentation style used byQXmlFormatter remains loosely defined and may change in future versions of Qt. If a specific indentation style is required then either use the base classQXmlSerializer directly, or write your own subclass ofQXmlSerializer orQAbstractXmlReceiver. Alternatively, you can subclassQXmlFormatter and 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);

Member Function Documentation

QXmlFormatter::QXmlFormatter(constQXmlQuery & query,QIODevice * outputDevice)

Constructs a formatter that uses the name pool and message handler inquery, and writes the result tooutputDevice as formatted XML.

outputDevice is passed directly toQXmlSerializer's constructor.

See alsoQXmlSerializer.

[virtual]void QXmlFormatter::atomicValue(constQVariant & value)

Reimplemented fromQAbstractXmlReceiver::atomicValue().

[virtual]void QXmlFormatter::attribute(constQXmlName & name, constQStringRef & value)

Reimplemented fromQAbstractXmlReceiver::attribute().

[virtual]void QXmlFormatter::characters(constQStringRef & value)

Reimplemented fromQAbstractXmlReceiver::characters().

[virtual]void QXmlFormatter::comment(constQString & value)

Reimplemented fromQAbstractXmlReceiver::comment().

[virtual]void QXmlFormatter::endDocument()

Reimplemented fromQAbstractXmlReceiver::endDocument().

[virtual]void QXmlFormatter::endElement()

Reimplemented fromQAbstractXmlReceiver::endElement().

[virtual]void QXmlFormatter::endOfSequence()

Reimplemented fromQAbstractXmlReceiver::endOfSequence().

int QXmlFormatter::indentationDepth() const

Returns the number of spacesQXmlFormatter will output for each indentation level. The default is four.

See alsosetIndentationDepth().

[virtual]void QXmlFormatter::processingInstruction(constQXmlName & name, constQString & value)

Reimplemented fromQAbstractXmlReceiver::processingInstruction().

void QXmlFormatter::setIndentationDepth(int depth)

Setsdepth to be the number of spacesQXmlFormatter will output for level of indentation. The default is four.

See alsoindentationDepth().

[virtual]void QXmlFormatter::startDocument()

Reimplemented fromQAbstractXmlReceiver::startDocument().

[virtual]void QXmlFormatter::startElement(constQXmlName & name)

Reimplemented fromQAbstractXmlReceiver::startElement().

[virtual]void QXmlFormatter::startOfSequence()

Reimplemented fromQAbstractXmlReceiver::startOfSequence().

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp