5 This file is part of KIllustrator.
6 Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de)
8 modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April ยด99
23 #include "koxml_config.h"
27 * The XMLWriter class provides support for writing XML streams.
28 * It contains methods for output XML elements with attributes.
32 * KOXML_OSTREAM os (fname);
33 * XmlWriter xml (os); // writes the XML header
35 * xml.startTag ("head"); // writes <head>
37 * // write <layout format="a4" orientation="landscape">
38 * xml.startTag ("layout", false);
39 * xml.addAttribute ("format", "a4");
40 * xml.addAttribute ("orientation", "landscape");
41 * xml.closeTag (true);
44 * @short A helper class for writing XML.
45 * @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de)
52 * Create a XmlWriter instance for the given output stream.
54 * @param os The open output stream for writing.
56 XmlWriter (KOXML_OSTREAM
& os
);
64 * Write an element with the given ID to the XML stream. Attributes
67 * @param id The element ID.
68 * @param closeIt If @p true the tag is closed by >,
70 * @param empty If @p true an empty element is written, which
72 * @param eol If @p true an eol char is appended
73 * even if autoendl is false
75 void startTag (KOXML_STRING id
, bool closeIt
= true, bool empty
= false, bool eol
= false);
78 * Write the end tag according to the given element ID or to the
79 * last opened element.
81 * @param id The element ID. If @p "" the last opened
82 * element is ended. (default).
83 * @param eol If @p true an eol char is appended
84 * even if autoendl is false
86 void endTag (KOXML_STRING id
= "", bool eol
= false);
89 * flag, indicating to automatically append end-of-line character after
92 * @param auto If @p true, append eol character. Otherwise caller has to do it
94 void setAutoEndl (const bool flag
= true);
97 * append end-of-line char to stream
102 * Close the current open element.
104 * @param empty If @p true an empty element is closed.
105 * @param eol If @p true an eol char is appended
106 * even if autoendl is false
108 void closeTag (bool empty
= false, bool eol
= false);
111 * Add an attribute with the given value to the current element.
112 * This method doesn't check, if an element is open.
114 * @param name The attribute name.
115 * @param value The string value of the attribute.
117 void addAttribute (KOXML_STRING name
, const KOXML_STRING
& value
);
120 * Add an attribute with the given value to the current element.
121 * This method doesn't check, if an element is open.
123 * @param name The attribute name.
124 * @param value The integer value of the attribute.
126 void addAttribute (KOXML_STRING name
, int value
);
129 * Add an attribute with the given value to the current element.
130 * This method doesn't check, if an element is open.
132 * @param name The attribute name.
133 * @param value The float value od the attribute.
135 void addAttribute (KOXML_STRING name
, float value
);
138 * Add an attribute with the given value to the current element.
139 * This method doesn't check, if an element is open.
141 * @param name The attribute name.
142 * @param value The double value of the attribute.
144 void addAttribute (KOXML_STRING name
, double value
);
147 * Write text to the XML stream. The method encodes the special
148 * characters @p <, @p > and @p &.
152 void writeText (KOXML_STRING s
);
155 * Write a tag to the XML stream.
157 * @param s The tag without the brackets.
159 void writeTag (KOXML_STRING s
);
162 * indents next text string with some spaces
164 * @param i number of spaces to indent
169 * Flush the XML output stream.
173 #ifndef KOXML_USE_STL
175 * Get the raw output stream.
177 inline QIODevice
*stream () { return strm
.device(); }
181 stack
<KOXML_STRING
, vector
<KOXML_STRING
> > lastTags
;