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
10 -----------------------------------------------------------------------
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Library General Public License as
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU Library General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include "XmlWriter.h"
30 XmlWriter::XmlWriter (KOXML_OSTREAM
& os
)
36 strm
<< "<?xml version=\"1.0\"?>" << endl
; // "encoding=UTF8"
40 XmlWriter::~XmlWriter () {
45 void XmlWriter::startTag (KOXML_STRING id
, bool closeIt
, bool empty
, bool eol
)
58 if (eol
|| autoendl
) {
67 void XmlWriter::endTag (KOXML_STRING id
, bool eol
)
73 KOXML_STRING tag
= lastTags
.top ();
78 if (eol
|| autoendl
) {
85 void XmlWriter::closeTag (bool empty
, bool eol
)
92 if (eol
|| autoendl
) {
100 void XmlWriter::setAutoEndl (const bool flag
)
106 void XmlWriter::endline()
114 void XmlWriter::addAttribute (KOXML_STRING name
, const KOXML_STRING
& value
)
118 KOXML_STRING val
= value
;
119 // escape dangerous characters in sgml-style
121 while ((pos
= val
.find ('&', pos
)) >= 0) {
122 KOXML_STRING_INSERT( val
, pos
+1, "amp;");
123 pos
+= 5; // skip &
126 while ((pos
= val
.find ('<', pos
)) >= 0) {
127 KOXML_STRING_REMOVE( val
, pos
, 1);
128 KOXML_STRING_INSERT( val
, pos
, "<");
129 pos
+= 4; // skip &nl;
132 while ((pos
= val
.find ('\n', pos
)) >= 0) {
133 KOXML_STRING_REMOVE( val
, pos
, 1);
134 KOXML_STRING_INSERT( val
, pos
, "&nl;");
135 pos
+= 4; // skip &nl;
138 while ((pos
= val
.find ('\r', pos
)) >= 0) {
139 KOXML_STRING_REMOVE( val
, pos
, 1);
140 KOXML_STRING_INSERT( val
, pos
+1, "lf;");
141 pos
+= 4; // skip &lf;
144 while ((pos
= val
.find ('\"', pos
)) >= 0) {
145 KOXML_STRING_REMOVE( val
, pos
, 1);
146 KOXML_STRING_INSERT( val
, pos
, """);
147 pos
+= 6; // skip &qout;
151 strm
<< name
<< "=\"";
157 void XmlWriter::addAttribute (KOXML_STRING name
, int value
)
159 if (name
.length() == 0)
163 strm
<< name
<< "=\"";
169 void XmlWriter::addAttribute (KOXML_STRING name
, float value
)
171 if (name
.length() == 0)
175 strm
<< name
<< "=\"";
181 void XmlWriter::addAttribute (KOXML_STRING name
, double value
)
183 if (name
.length() == 0)
187 strm
<< name
<< "=\"";
193 void XmlWriter::writeText (KOXML_STRING c
)
196 while (i
< (int) c
.length()) {
199 else if (c
[i
] == '&')
201 else if (c
[i
] == '>')
203 else if (c
[i
] == '\"' || c
[i
] == '\'' || c
[i
] == '`') {
214 else if (c
[i
] == '\n') {
220 else if (c
[i
] == '\r') {
233 void XmlWriter::indent (int i
)
240 void XmlWriter::writeTag (KOXML_STRING s
)
248 void XmlWriter::flush ()
250 #ifndef KOXML_USE_STL