Qt 4.8
Public Functions | Protected Functions | Private Types | Private Functions | List of all members
QXmlSerializer Class Reference

The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML. More...

#include <qxmlserializer.h>

Inheritance diagram for QXmlSerializer:
QAbstractXmlReceiver QXmlFormatter

Public Functions

virtual void atomicValue (const QVariant &value)
 Reimplemented Function More...
 
virtual void attribute (const QXmlName &name, const QStringRef &value)
 Reimplemented Function More...
 
virtual void characters (const QStringRef &value)
 Reimplemented Function More...
 
const QTextCodeccodec () const
 Returns the codec being used by the serializer for encoding its XML output. More...
 
virtual void comment (const QString &value)
 Reimplemented Function More...
 
virtual void endDocument ()
 Reimplemented Function More...
 
virtual void endElement ()
 Reimplemented Function More...
 
virtual void endOfSequence ()
 Reimplemented Function More...
 
virtual void item (const QPatternist::Item &item)
 
virtual void namespaceBinding (const QXmlName &nb)
 Reimplemented Function More...
 
QIODeviceoutputDevice () const
 Returns a pointer to the output device. More...
 
virtual void processingInstruction (const QXmlName &name, const QString &value)
 Reimplemented Function More...
 
 QXmlSerializer (const QXmlQuery &query, QIODevice *outputDevice)
 Constructs a serializer that uses the name pool and message handler in query, and writes the output to outputDevice. More...
 
void setCodec (const QTextCodec *codec)
 Sets the codec the serializer will use for encoding its XML output. More...
 
virtual void startDocument ()
 Reimplemented Function More...
 
virtual void startElement (const QXmlName &name)
 Reimplemented Function More...
 
virtual void startOfSequence ()
 Reimplemented Function More...
 
- Public Functions inherited from QAbstractXmlReceiver
 QAbstractXmlReceiver ()
 Constructs an abstract xml receiver. More...
 
virtual void whitespaceOnly (const QStringRef &value)
 This function may be called instead of characters() if, and only if, value consists only of whitespace. More...
 
virtual ~QAbstractXmlReceiver ()
 Destroys the xml receiver. More...
 

Protected Functions

 QXmlSerializer (QAbstractXmlReceiverPrivate *d)
 
- Protected Functions inherited from QAbstractXmlReceiver
 QAbstractXmlReceiver (QAbstractXmlReceiverPrivate *d)
 
void sendAsNode (const QPatternist::Item &outputItem)
 Treats outputItem as a node and calls the appropriate function, e. More...
 

Private Types

enum  State { BeforeDocumentElement, InsideDocumentElement }
 

Private Functions

bool atDocumentRoot () const
 
bool isBindingInScope (const QXmlName nb) const
 
void startContent ()
 
void write (const QXmlName &name)
 
void write (const char *const chars)
 
void write (const QString &content)
 
void writeEscaped (const QString &toEscape)
 
void writeEscapedAttribute (const QString &toEscape)
 

Additional Inherited Members

- Protected Variables inherited from QAbstractXmlReceiver
QScopedPointer< QAbstractXmlReceiverPrivated_ptr
 

Detailed Description

The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML.

Note
This class or function is reentrant.
Since
4.4

QXmlSerializer translates an XQuery Sequence, usually the output of an QXmlQuery, into XML. Consider the example:

QXmlQuery query;
query.setQuery("doc('index.html')/html/body/p[1]");
QXmlSerializer serializer(query, myOutputDevice);
query.evaluateTo(&serializer);

First it constructs a QXmlQuery {query} that gets the first paragraph from document index.html. Then it constructs an instance of this class with the QXmlQuery {query} and QIODevice {myOutputDevice}. Finally, it QXmlQuery::evaluateTo() {evaluates} the QXmlQuery {query}, 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 QIODevice {myOutputDevice}.

QXmlSerializer will:

If an error occurs during serialization, result is undefined unless the serializer is driven through a call to QXmlQuery::evaluateTo().

If the generated XML should be indented and formatted for reading, use QXmlFormatter.

See also
{http://www.w3.org/TR/xslt-xquery-serialization/}{XSLT 2.0 and XQuery 1.0 Serialization}
QXmlFormatter

Definition at line 58 of file qxmlserializer.h.

Enumerations

◆ State

enum QXmlSerializer::State
private

Where in the document the QXmlSerializer is currently working.

Enumerator
BeforeDocumentElement 

Before the document element. This is the XML prolog where the XML declaration, and possibly comments and processing instructions are found.

InsideDocumentElement 

This is inside the document element, at any level.

Definition at line 103 of file qxmlserializer.h.

Constructors and Destructors

◆ QXmlSerializer() [1/2]

QXmlSerializer::QXmlSerializer ( const QXmlQuery query,
QIODevice outputDevice 
)

Constructs a serializer that uses the name pool and message handler in query, and writes the output to outputDevice.

outputDevice must be a valid, non-null device that is open in write mode, otherwise behavior is undefined.

outputDevice 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. QXmlSerializer does not take ownership of outputDevice.

Definition at line 159 of file qxmlserializer.cpp.

160  : QAbstractXmlReceiver(new QXmlSerializerPrivate(query, outputDevice))
161 {
162  if(!outputDevice)
163  {
164  qWarning("outputDevice cannot be null.");
165  return;
166  }
167 
168  if(!outputDevice->isWritable())
169  {
170  qWarning("outputDevice must be opened in write mode.");
171  return;
172  }
173 }
QAbstractXmlReceiver()
Constructs an abstract xml receiver.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
Definition: qiodevice.cpp:558
Q_CORE_EXPORT void qWarning(const char *,...)

◆ QXmlSerializer() [2/2]

QXmlSerializer::QXmlSerializer ( QAbstractXmlReceiverPrivate d)
protected
Warning
This function is not part of the public interface.

Definition at line 178 of file qxmlserializer.cpp.

179 {
180 }
QAbstractXmlReceiver()
Constructs an abstract xml receiver.

Functions

◆ atDocumentRoot()

bool QXmlSerializer::atDocumentRoot ( ) const
inlineprivate

If the current state is neither BeforeDocumentElement or AfterDocumentElement.

Warning
This function is not part of the public interface.

Definition at line 185 of file qxmlserializer.cpp.

Referenced by attribute(), and startElement().

186 {
187  Q_D(const QXmlSerializer);
188  return d->state == BeforeDocumentElement ||
189  (d->state == InsideDocumentElement && d->hasClosedElement.size() == 1);
190 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ atomicValue()

void QXmlSerializer::atomicValue ( const QVariant value)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 575 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::atomicValue().

576 {
577  Q_UNUSED(value);
578 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ attribute()

void QXmlSerializer::attribute ( const QXmlName name,
const QStringRef value 
)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 366 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::attribute().

368 {
370  Q_ASSERT(!name.isNull());
371 
372  /* Ensure that the namespace URI used in the name gets outputted. */
373  {
374  /* Since attributes doesn't pick up the default namespace, a
375  * namespace declaration would cause trouble if we output it. */
376  if(name.prefix() != StandardPrefixes::empty)
377  namespaceBinding(name);
378  }
379 
380  if(atDocumentRoot())
381  {
382  Q_UNUSED(d);
383  d->query.d->staticContext()->error(QtXmlPatterns::tr(
384  "Attribute %1 can't be serialized because it appears at "
385  "the top level.").arg(formatKeyword(d->np, name)),
386  ReportContext::SENR0001,
387  d->query.d->expression().data());
388  }
389  else
390  {
391  d->write(' ');
392  write(name);
393  write("=\"");
395  d->write('"');
396  }
397 }
double d
Definition: qnumeric_p.h:62
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
QString formatKeyword(const QString &keyword)
void writeEscapedAttribute(const QString &toEscape)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
virtual void namespaceBinding(const QXmlName &nb)
Reimplemented Function
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
bool atDocumentRoot() const
void write(const QXmlName &name)
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ characters()

void QXmlSerializer::characters ( const QStringRef value)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 507 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::endOfSequence(), and QXmlFormatter::startFormattingContent().

508 {
510  d->isPreviousAtomic = false;
511  startContent();
512  writeEscaped(value.toString());
513 }
double d
Definition: qnumeric_p.h:62
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
void writeEscaped(const QString &toEscape)
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ codec()

const QTextCodec * QXmlSerializer::codec ( ) const

Returns the codec being used by the serializer for encoding its XML output.

See also
setCodec()

Definition at line 632 of file qxmlserializer.cpp.

633 {
634  Q_D(const QXmlSerializer);
635  return d->codec;
636 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ comment()

void QXmlSerializer::comment ( const QString value)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 489 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::comment().

490 {
492  Q_ASSERT_X(!value.contains(QLatin1String("--")),
493  Q_FUNC_INFO,
494  "Invalid input; it's the caller's responsibility to ensure "
495  "the input is correct.");
496 
497  startContent();
498  write("<!--");
499  write(value);
500  write("-->");
501  d->isPreviousAtomic = false;
502 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
void write(const QXmlName &name)
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ endDocument()

void QXmlSerializer::endDocument ( )
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 592 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::endDocument().

593 {
595  d->isPreviousAtomic = false;
596 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ endElement()

void QXmlSerializer::endElement ( )
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 345 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::endElement().

346 {
348  const QPair<QXmlName, bool> e(d->hasClosedElement.pop());
349  d->namespaces.pop();
350 
351  if(e.second)
352  {
353  write("</");
354  write(e.first);
355  d->write('>');
356  }
357  else
358  write("/>");
359 
360  d->isPreviousAtomic = false;
361 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
void write(const QXmlName &name)

◆ endOfSequence()

void QXmlSerializer::endOfSequence ( )
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 648 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::endOfSequence().

649 {
650  /* If this function is changed to flush or close or something like that,
651  * take into consideration QXmlFormatter, especially
652  * QXmlFormatter::endOfSequence().
653  */
654 }

◆ isBindingInScope()

bool QXmlSerializer::isBindingInScope ( const QXmlName  nb) const
inlineprivate
Warning
This function is not part of the public interface.

Definition at line 402 of file qxmlserializer.cpp.

Referenced by namespaceBinding().

403 {
404  Q_D(const QXmlSerializer);
405  const int levelLen = d->namespaces.size();
406 
407  if(nb.prefix() == StandardPrefixes::empty)
408  {
409  for(int lvl = levelLen - 1; lvl >= 0; --lvl)
410  {
411  const QVector<QXmlName> &scope = d->namespaces.at(lvl);
412  const int vectorLen = scope.size();
413 
414  for(int s = vectorLen - 1; s >= 0; --s)
415  {
416  const QXmlName &nsb = scope.at(s);
417 
418  if(nsb.prefix() == StandardPrefixes::empty)
419  return nsb.namespaceURI() == nb.namespaceURI();
420  }
421  }
422  }
423  else
424  {
425  for(int lvl = 0; lvl < levelLen; ++lvl)
426  {
427  const QVector<QXmlName> &scope = d->namespaces.at(lvl);
428  const int vectorLen = scope.size();
429 
430  for(int s = 0; s < vectorLen; ++s)
431  {
432  const QXmlName &n = scope.at(s);
433  if (n.prefix() == nb.prefix() &&
434  n.namespaceURI() == nb.namespaceURI())
435  return true;
436  }
437  }
438  }
439 
440  return false;
441 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ item()

void QXmlSerializer::item ( const QPatternist::Item outputItem)
virtual
Warning
This function is not part of the public interface.

Reimplemented from QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 540 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::item().

541 {
543 
544  if(outputItem.isAtomicValue())
545  {
546  if(d->isPreviousAtomic)
547  {
548  startContent();
549  d->write(' ');
550  writeEscaped(outputItem.stringValue());
551  }
552  else
553  {
554  d->isPreviousAtomic = true;
555  const QString value(outputItem.stringValue());
556 
557  if(!value.isEmpty())
558  {
559  startContent();
560  writeEscaped(value);
561  }
562  }
563  }
564  else
565  {
566  startContent();
567  Q_ASSERT(outputItem.isNode());
568  sendAsNode(outputItem);
569  }
570 }
double d
Definition: qnumeric_p.h:62
void writeEscaped(const QString &toEscape)
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isNode() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:349
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void sendAsNode(const QPatternist::Item &outputItem)
Treats outputItem as a node and calls the appropriate function, e.
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
bool isAtomicValue() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:335

◆ namespaceBinding()

void QXmlSerializer::namespaceBinding ( const QXmlName nb)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Definition at line 446 of file qxmlserializer.cpp.

Referenced by attribute(), and startElement().

447 {
448  /*
449  * Writes out \a nb.
450  *
451  * Namespace bindings aren't looked up in a cache, because
452  * we typically receive very few.
453  */
454 
457  "It makes no sense to pass a null QXmlName.");
458 
459  Q_ASSERT_X((nb.namespaceURI() != StandardNamespaces::empty) ||
460  (nb.prefix() == StandardPrefixes::empty),
461  Q_FUNC_INFO,
462  "Undeclarations of prefixes aren't allowed in XML 1.0 "
463  "and aren't supposed to be received.");
464 
466  return;
467 
468  if(isBindingInScope(nb))
469  return;
470 
471  d->namespaces.top().append(nb);
472 
473  if(nb.prefix() == StandardPrefixes::empty)
474  write(" xmlns");
475  else
476  {
477  write(" xmlns:");
478  write(d->np->stringForPrefix(nb.prefix()));
479  }
480 
481  write("=\"");
482  writeEscapedAttribute(d->np->stringForNamespace(nb.namespaceURI()));
483  d->write('"');
484 }
double d
Definition: qnumeric_p.h:62
void writeEscapedAttribute(const QString &toEscape)
#define Q_D(Class)
Definition: qglobal.h:2482
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
bool isBindingInScope(const QXmlName nb) const
void write(const QXmlName &name)
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ outputDevice()

QIODevice * QXmlSerializer::outputDevice ( ) const

Returns a pointer to the output device.

There is no corresponding function to set the output device, because the output device must be passed to the constructor. The serializer does not take ownership of its IO device.

Definition at line 605 of file qxmlserializer.cpp.

606 {
607  Q_D(const QXmlSerializer);
608  return d->device;
609 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ processingInstruction()

void QXmlSerializer::processingInstruction ( const QXmlName name,
const QString value 
)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 518 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::processingInstruction().

520 {
522  Q_ASSERT_X(!value.contains(QLatin1String("?>")),
523  Q_FUNC_INFO,
524  "Invalid input; it's the caller's responsibility to ensure "
525  "the input is correct.");
526 
527  startContent();
528  write("<?");
529  write(name);
530  d->write(' ');
531  write(value);
532  write("?>");
533 
534  d->isPreviousAtomic = false;
535 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
void write(const QXmlName &name)
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ setCodec()

void QXmlSerializer::setCodec ( const QTextCodec outputCodec)

Sets the codec the serializer will use for encoding its XML output.

The output codec is set to outputCodec. By default, the output codec is set to the one for UTF-8. The serializer does not take ownership of the codec.

See also
codec()

Definition at line 620 of file qxmlserializer.cpp.

621 {
623  d->codec = outputCodec;
624 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ startContent()

void QXmlSerializer::startContent ( )
inlineprivate

Closes any open element start tag. Must be called before outputting any element content.

Warning
This function is not part of the public interface.

Definition at line 195 of file qxmlserializer.cpp.

Referenced by characters(), comment(), item(), processingInstruction(), and startElement().

196 {
198  if (!d->hasClosedElement.top().second) {
199  d->write('>');
200  d->hasClosedElement.top().second = true;
201  }
202 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ startDocument()

void QXmlSerializer::startDocument ( )
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 583 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::startDocument().

584 {
586  d->isPreviousAtomic = false;
587 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ startElement()

void QXmlSerializer::startElement ( const QXmlName name)
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 307 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::startElement().

308 {
310  Q_ASSERT(d->device);
311  Q_ASSERT(d->device->isWritable());
312  Q_ASSERT(d->codec);
313  Q_ASSERT(!name.isNull());
314 
315  d->namespaces.push(QVector<QXmlName>());
316 
317  if(atDocumentRoot())
318  {
319  if(d->state == BeforeDocumentElement)
320  d->state = InsideDocumentElement;
321  else if(d->state != InsideDocumentElement)
322  {
323  d->query.d->staticContext()->error(QtXmlPatterns::tr(
324  "Element %1 can't be serialized because it appears outside "
325  "the document element.").arg(formatKeyword(d->np, name)),
326  ReportContext::SENR0001,
327  d->query.d->expression().data());
328  }
329  }
330 
331  startContent();
332  d->write('<');
333  write(name);
334 
335  /* Ensure that the namespace URI used in the name gets outputted. */
336  namespaceBinding(name);
337 
338  d->hasClosedElement.push(qMakePair(name, false));
339  d->isPreviousAtomic = false;
340 }
double d
Definition: qnumeric_p.h:62
QString formatKeyword(const QString &keyword)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
virtual void namespaceBinding(const QXmlName &nb)
Reimplemented Function
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
bool atDocumentRoot() const
void write(const QXmlName &name)
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ startOfSequence()

void QXmlSerializer::startOfSequence ( )
virtual

Reimplemented Function

Implements QAbstractXmlReceiver.

Reimplemented in QXmlFormatter.

Definition at line 641 of file qxmlserializer.cpp.

Referenced by QXmlFormatter::startOfSequence().

642 {
643 }

◆ write() [1/3]

void QXmlSerializer::write ( const QXmlName name)
inlineprivate

Writes out name.

Warning
This function is not part of the public interface.

Definition at line 276 of file qxmlserializer.cpp.

Referenced by attribute(), comment(), endElement(), namespaceBinding(), processingInstruction(), startElement(), writeEscaped(), and writeEscapedAttribute().

277 {
279  const QByteArray &cell = d->nameCache[name.code()];
280 
281  if(cell.isNull())
282  {
283  QByteArray &mutableCell = d->nameCache[name.code()];
284 
285  const QString content(d->np->toLexical(name));
286  mutableCell = d->codec->fromUnicode(content.constData(),
287  content.length(),
288  &d->converterState);
289  d->device->write(mutableCell);
290  }
291  else
292  d->device->write(cell);
293 }
double d
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
Code code() const
Returns the internal code that contains the id codes for the local name, prefix and namespace URI...
Definition: qnamepool_p.h:528

◆ write() [2/3]

void QXmlSerializer::write ( const char *const  chars)
inlineprivate
Warning
This function is not part of the public interface.

Definition at line 298 of file qxmlserializer.cpp.

299 {
301  d->device->write(chars);
302 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...

◆ write() [3/3]

void QXmlSerializer::write ( const QString content)
inlineprivate

Encodes and writes out content.

Warning
This function is not part of the public interface.

Definition at line 267 of file qxmlserializer.cpp.

268 {
270  d->device->write(d->codec->fromUnicode(content.constData(), content.length(), &d->converterState));
271 }
double d
Definition: qnumeric_p.h:62
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define Q_D(Class)
Definition: qglobal.h:2482
The QXmlSerializer class is an implementation of QAbstractXmlReceiver for transforming XQuery output ...
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ writeEscaped()

void QXmlSerializer::writeEscaped ( const QString toEscape)
private

Escapes content intended as text nodes for elements.

Warning
This function is not part of the public interface.

Definition at line 207 of file qxmlserializer.cpp.

Referenced by characters(), and item().

208 {
209  if(toEscape.isEmpty()) /* Early exit. */
210  return;
211 
212  QString result;
213  result.reserve(int(toEscape.length() * 1.1));
214  const int length = toEscape.length();
215 
216  for(int i = 0; i < length; ++i)
217  {
218  const QChar c(toEscape.at(i));
219 
220  if(c == QLatin1Char('<'))
221  result += QLatin1String("&lt;");
222  else if(c == QLatin1Char('>'))
223  result += QLatin1String("&gt;");
224  else if(c == QLatin1Char('&'))
225  result += QLatin1String("&amp;");
226  else
227  result += toEscape.at(i);
228  }
229 
230  write(result);
231 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void write(const QXmlName &name)

◆ writeEscapedAttribute()

void QXmlSerializer::writeEscapedAttribute ( const QString toEscape)
inlineprivate

Identical to writeEscaped(), but also escapes quotes.

Warning
This function is not part of the public interface.

Definition at line 236 of file qxmlserializer.cpp.

Referenced by attribute(), and namespaceBinding().

237 {
238  if(toEscape.isEmpty()) /* Early exit. */
239  return;
240 
241  QString result;
242  result.reserve(int(toEscape.length() * 1.1));
243  const int length = toEscape.length();
244 
245  for(int i = 0; i < length; ++i)
246  {
247  const QChar c(toEscape.at(i));
248 
249  if(c == QLatin1Char('<'))
250  result += QLatin1String("&lt;");
251  else if(c == QLatin1Char('>'))
252  result += QLatin1String("&gt;");
253  else if(c == QLatin1Char('&'))
254  result += QLatin1String("&amp;");
255  else if(c == QLatin1Char('"'))
256  result += QLatin1String("&quot;");
257  else
258  result += toEscape.at(i);
259  }
260 
261  write(result);
262 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void write(const QXmlName &name)

The documentation for this class was generated from the following files: