lib

KoXmlWriter Class Reference

#include <KoXmlWriter.h>

Public Member Functions

 KoXmlWriter (TQIODevice *dev, int indentLevel=0)
 
 ~KoXmlWriter ()
 
TQIODevice * device () const
 
void startDocument (const char *rootElemName, const char *publicId=0, const char *systemId=0)
 
void endDocument ()
 
void startElement (const char *tagName, bool indentInside=true)
 
void addAttribute (const char *attrName, const TQString &value)
 
void addAttribute (const char *attrName, int value)
 
void addAttribute (const char *attrName, uint value)
 
void addAttribute (const char *attrName, double value)
 
void addAttributePt (const char *attrName, double value)
 
void addAttribute (const char *attrName, const TQCString &value)
 
void addAttribute (const char *attrName, const char *value)
 
void endElement ()
 
void addTextNode (const TQString &str)
 
void addTextNode (const TQCString &cstr)
 
void addTextNode (const char *cstr)
 
void addProcessingInstruction (const char *cstr)
 
void addCompleteElement (const char *cstr)
 
void addCompleteElement (TQIODevice *dev)
 
void addManifestEntry (const TQString &fullPath, const TQString &mediaType)
 
void addConfigItem (const TQString &configName, const TQString &value)
 
void addConfigItem (const TQString &configName, bool value)
 
void addConfigItem (const TQString &configName, int value)
 
void addConfigItem (const TQString &configName, double value)
 
void addConfigItem (const TQString &configName, long value)
 
void addConfigItem (const TQString &configName, short value)
 
void addTextSpan (const TQString &text)
 
void addTextSpan (const TQString &text, const TQMap< int, int > &tabCache)
 
int indentLevel () const
 

Detailed Description

A class for writing out XML (to any TQIODevice), with a special attention on performance.

The XML is being written out along the way, which avoids requiring the entire document in memory (like TQDom does), and avoids using TQTextStream at all (which in TQt3 has major performance issues when converting to utf8).

Definition at line 36 of file KoXmlWriter.h.

Constructor & Destructor Documentation

◆ KoXmlWriter()

KoXmlWriter::KoXmlWriter ( TQIODevice *  dev,
int  indentLevel = 0 
)

Create a KoXmlWriter instance to write out an XML document into the given TQIODevice.

Definition at line 29 of file KoXmlWriter.cpp.

◆ ~KoXmlWriter()

KoXmlWriter::~KoXmlWriter ( )

Destructor.

Definition at line 44 of file KoXmlWriter.cpp.

Member Function Documentation

◆ addAttribute() [1/6]

void KoXmlWriter::addAttribute ( const char *  attrName,
const char *  value 
)

Add an attribute to the current element.

Definition at line 180 of file KoXmlWriter.cpp.

◆ addAttribute() [2/6]

void KoXmlWriter::addAttribute ( const char *  attrName,
const TQCString &  value 
)
inline

Overloaded version of the one taking a const char* argument, for convenience.

Definition at line 110 of file KoXmlWriter.h.

◆ addAttribute() [3/6]

void KoXmlWriter::addAttribute ( const char *  attrName,
const TQString &  value 
)
inline

Overloaded version of addAttribute( const char*, const char* ), which is a bit slower because it needs to convert value to utf8 first.

Definition at line 76 of file KoXmlWriter.h.

◆ addAttribute() [4/6]

void KoXmlWriter::addAttribute ( const char *  attrName,
double  value 
)

Add an attribute whose value is a floating point number The number is written out with the highest possible precision (unlike TQString::number and setNum, which default to 6 digits)

Definition at line 192 of file KoXmlWriter.cpp.

◆ addAttribute() [5/6]

void KoXmlWriter::addAttribute ( const char *  attrName,
int  value 
)
inline

Add an attribute whose value is an integer.

Definition at line 82 of file KoXmlWriter.h.

◆ addAttribute() [6/6]

void KoXmlWriter::addAttribute ( const char *  attrName,
uint  value 
)
inline

Add an attribute whose value is an unsigned integer.

Definition at line 90 of file KoXmlWriter.h.

◆ addAttributePt()

void KoXmlWriter::addAttributePt ( const char *  attrName,
double  value 
)

Add an attribute which represents a distance, measured in pt The number is written out with the highest possible precision (unlike TQString::number and setNum, which default to 6 digits), and the unit name ("pt") is appended to it.

Definition at line 199 of file KoXmlWriter.cpp.

◆ addCompleteElement() [1/2]

void KoXmlWriter::addCompleteElement ( const char *  cstr)

This is quite a special-purpose method, not for everyday use.

It adds a complete element (with its attributes and child elements) as a child of the current element. The string is supposed to be escaped for XML already, so it will usually come from another KoXmlWriter.

Definition at line 116 of file KoXmlWriter.cpp.

◆ addCompleteElement() [2/2]

void KoXmlWriter::addCompleteElement ( TQIODevice *  dev)

This is quite a special-purpose method, not for everyday use.

It adds a complete element (with its attributes and child elements) as a child of the current element. The iodevice is supposed to be escaped for XML already, so it will usually come from another KoXmlWriter. This is usually used with KTempFile.

Definition at line 123 of file KoXmlWriter.cpp.

◆ addConfigItem() [1/6]

void KoXmlWriter::addConfigItem ( const TQString &  configName,
bool  value 
)
Note
OASIS-specific

Definition at line 300 of file KoXmlWriter.cpp.

◆ addConfigItem() [2/6]

void KoXmlWriter::addConfigItem ( const TQString &  configName,
const TQString &  value 
)

Special helper for writing config item into settings.xml.

Note
OASIS-specific

Definition at line 291 of file KoXmlWriter.cpp.

◆ addConfigItem() [3/6]

void KoXmlWriter::addConfigItem ( const TQString &  configName,
double  value 
)
Note
OASIS-specific

Definition at line 318 of file KoXmlWriter.cpp.

◆ addConfigItem() [4/6]

void KoXmlWriter::addConfigItem ( const TQString &  configName,
int  value 
)
Note
OASIS-specific

Definition at line 309 of file KoXmlWriter.cpp.

◆ addConfigItem() [5/6]

void KoXmlWriter::addConfigItem ( const TQString &  configName,
long  value 
)
Note
OASIS-specific

Definition at line 327 of file KoXmlWriter.cpp.

◆ addConfigItem() [6/6]

void KoXmlWriter::addConfigItem ( const TQString &  configName,
short  value 
)
Note
OASIS-specific

Definition at line 336 of file KoXmlWriter.cpp.

◆ addManifestEntry()

void KoXmlWriter::addManifestEntry ( const TQString &  fullPath,
const TQString &  mediaType 
)

Special helper for writing "manifest" files This is equivalent to startElement/2*addAttribute/endElement This API will probably have to change (or not be used anymore) when we add support for encrypting/signing.

Note
OASIS-specific

Definition at line 283 of file KoXmlWriter.cpp.

◆ addProcessingInstruction()

void KoXmlWriter::addProcessingInstruction ( const char *  cstr)

Adds a processing instruction.

This writes a processing instruction, like <?foo bar blah?>, where foo is the target, and the rest is the data.

Processing instructions are used in XML to keep processor-specific information in the text of the document.

Definition at line 172 of file KoXmlWriter.cpp.

◆ addTextNode() [1/3]

void KoXmlWriter::addTextNode ( const char *  cstr)

Adds a text node as a child of the current element.

This is appends the litteral content of str to the contents of the element. E.g. addTextNode( "foo" ) inside a <p> element gives <p>foo</p>, and startElement( "b" ); endElement( "b" ); addTextNode( "foo" ) gives <p><b/>foo</p>

Definition at line 163 of file KoXmlWriter.cpp.

◆ addTextNode() [2/3]

void KoXmlWriter::addTextNode ( const TQCString &  cstr)
inline

Overloaded version of the one taking a const char* argument.

Definition at line 130 of file KoXmlWriter.h.

◆ addTextNode() [3/3]

void KoXmlWriter::addTextNode ( const TQString &  str)
inline

Overloaded version of addTextNode( const char* ), which is a bit slower because it needs to convert str to utf8 first.

Definition at line 126 of file KoXmlWriter.h.

◆ addTextSpan() [1/2]

void KoXmlWriter::addTextSpan ( const TQString &  text)

Adds a text span as nodes of the current element.

Unlike KoXmlWriter::addTextNode it handles tabulations, linebreaks, and multiple spaces by using the appropriate OASIS tags.

Parameters
textthe text to write
Note
OASIS-specific

Definition at line 345 of file KoXmlWriter.cpp.

◆ addTextSpan() [2/2]

void KoXmlWriter::addTextSpan ( const TQString &  text,
const TQMap< int, int > &  tabCache 
)

Overloaded version of addTextSpan which takes an additional tabCache map.

Parameters
textthe text to write
tabCacheoptional map allowing to find a tab for a given character index
Note
OASIS-specific

Definition at line 351 of file KoXmlWriter.cpp.

◆ device()

TQIODevice * KoXmlWriter::device ( ) const
inline

Definition at line 48 of file KoXmlWriter.h.

◆ endDocument()

void KoXmlWriter::endDocument ( )

Call this to terminate an XML document.

Definition at line 68 of file KoXmlWriter.cpp.

◆ endElement()

void KoXmlWriter::endElement ( )

Terminate the current element.

After this you should start a new one (sibling), add a sibling text node, or close another one (end of siblings).

Definition at line 140 of file KoXmlWriter.cpp.

◆ indentLevel()

int KoXmlWriter::indentLevel ( ) const
inline
Returns
the current indentation level. Useful when creating a sub-KoXmlWriter (see addCompleteElement)

Definition at line 221 of file KoXmlWriter.h.

◆ startDocument()

void KoXmlWriter::startDocument ( const char *  rootElemName,
const char *  publicId = 0,
const char *  systemId = 0 
)

Start the XML document.

This writes out the <?xml?> tag with utf8 encoding, and the DOCTYPE.

Parameters
rootElemNamethe name of the root element, used in the DOCTYPE tag.
publicIdthe public identifier, e.g. "-//OpenOffice.org//DTD OfficeDocument 1.0//EN"
systemIdthe system identifier, e.g. "office.dtd" or a full URL to it.

Definition at line 50 of file KoXmlWriter.cpp.

◆ startElement()

void KoXmlWriter::startElement ( const char *  tagName,
bool  indentInside = true 
)

Start a new element, as a child of the current element.

Parameters
tagNamethe name of the tag. Warning: this string must remain alive until endElement, no copy is internally made. Usually tagName is a string constant so this is no problem anyway.
indentInsideif set to false, there will be no indentation inside this tag. This is useful for elements where whitespace matters.

Definition at line 103 of file KoXmlWriter.cpp.


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