Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
xmlwriter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include "xmlwriter.h"
4
5#include <QTextDocument>
6
8{
9 QDomImplementation implementation;
10 QDomDocumentType docType = implementation.createDocumentType(
11 "scribe-document", "scribe", "qt.nokia.com/scribe");
12
13 document = new QDomDocument(docType);
14
15 // ### This processing instruction is required to ensure that any kind
16 // of encoding is given when the document is written.
18 "xml", "version=\"1.0\" encoding=\"utf-8\"");
19 document->appendChild(process);
20
21 QDomElement documentElement = document->createElement("document");
22 document->appendChild(documentElement);
23
25 QTextBlock currentBlock = textDocument->begin();
26
27 while (currentBlock.isValid()) {
29 QDomElement blockElement = document->createElement("block");
30 document->appendChild(blockElement);
31
32 readFragment(currentBlock, blockElement, document);
33
35 processBlock(currentBlock);
37
39 currentBlock = currentBlock.next();
40 }
42
43 return document;
44}
45
46void XmlWriter::readFragment(const QTextBlock &currentBlock,
47 QDomElement blockElement,
48 QDomDocument *document)
49{
52 for (it = currentBlock.begin(); !(it.atEnd()); ++it) {
53 QTextFragment currentFragment = it.fragment();
54 if (currentFragment.isValid())
56 processFragment(currentFragment);
58
59 if (currentFragment.isValid()) {
60 QDomElement fragmentElement = document->createElement("fragment");
61 blockElement.appendChild(fragmentElement);
62
63 fragmentElement.setAttribute("length", currentFragment.length());
64 QDomText fragmentText = document->createTextNode(currentFragment.text());
65
66 fragmentElement.appendChild(fragmentText);
67 }
69 }
71}
72
73void XmlWriter::processBlock(const QTextBlock &currentBlock)
74{
75 // Dummy use of specified parameter currentBlock
76 QTextBlock localBlock;
77 localBlock = currentBlock;
78
79}
80
81void XmlWriter::processFragment(const QTextFragment &currentFragment)
82{
83 // Dummy use of specified parameter currentFragment
84 QTextFragment localFragment;
85 localFragment = currentFragment;
86}
\reentrant
Definition qdom.h:243
\reentrant
Definition qdom.h:269
QDomProcessingInstruction createProcessingInstruction(const QString &target, const QString &data)
Creates a new processing instruction that can be inserted into the document, e.g.
Definition qdom.cpp:6586
QDomElement createElement(const QString &tagName)
Creates a new element called tagName that can be inserted into the DOM tree, e.g.
Definition qdom.cpp:6505
\reentrant
Definition qdom.h:471
\reentrant
Definition qdom.h:60
QDomDocumentType createDocumentType(const QString &qName, const QString &publicId, const QString &systemId)
Creates a document type node for the name qName.
Definition qdom.cpp:486
QDomNode appendChild(const QDomNode &newChild)
Appends newChild as the node's last child.
Definition qdom.cpp:2063
\reentrant
Definition qdom.h:529
\reentrant
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
QTextBlock next() const
Returns the text block in the document after this block, or an empty text block if this is the last o...
QTextBlock begin() const
Returns the document's first text block.
\reentrant
QDomDocument * toXml()
Definition xmlwriter.cpp:7
QSet< QString >::iterator it