18 XMLWriter::XMLWriter(ostream* out,
string indentString,
string aDefaultNameSpace)
41 *
writer <<
"<?xml version=\"" << version.c_str() <<
"\" ";
42 if (encoding.compare(
"") != 0) {
44 *
writer <<
"encoding=\"" << encoding.c_str() <<
"\" ";
47 *
writer <<
"standalone=\"yes\" ";
56 cerr <<
"XMLWriter::ReferToDTD cannot be called twice" << endl;
59 *
writer <<
"<!DOCTYPE " << name.c_str() <<
" PUBLIC \"" << pid.c_str() <<
"\" \"" << ref.c_str() <<
"\">" << endl;
64 cerr <<
"XMLWriter::ReferToDTD cannot be called twice";
67 *
writer <<
"<!DOCTYPE " << name.c_str() <<
" SYSTEM \"" << system.c_str() <<
"\">" << endl;
72 if (!openTags.empty()) {
73 if (!force) cerr <<
"Not all tags were closed before closing XML document:" << endl;
74 while (!openTags.empty()) {
78 cerr <<
" </" << openTags.top().c_str() <<
">" << endl;
88 if (comment.find(
"--") != string::npos) {
89 cerr <<
"XMLWriter::printComment '--' sequence not allowed in comment" << endl;
109 if (openTags.empty() && dtdName.compare(
"") && dtdName.compare(name)) {
110 cerr <<
"XMLWriter::openTag(), First tag: '" << name <<
"' not equal to DTD id: '" << dtdName <<
"'" << endl;
112 *
writer <<
"<" << name.c_str();
120 if (openTags.empty()) {
122 cerr <<
"XMLWriter::closeTag(), No open tags" << endl;
124 string name = openTags.top();
127 *
writer <<
"</" << name.c_str() <<
">" << endl;
132 *
writer <<
"<" << name.c_str();
147 if (name ==
"value")
setAttribute(
"type", (std::string)
"Color");
152 if (name ==
"value")
setAttribute(
"type", (std::string)
"long");
157 if (name ==
"showlabel") {
161 if (name ==
"value")
setAttribute(
"type", (std::string)
"int");
167 if (name ==
"value")
setAttribute(
"type", (std::string)
"boolean");
172 if (name ==
"value")
setAttribute(
"type", (std::string)
"double");
177 int width = tagLength + 1;
178 bool extraIndent =
false;
179 for (map<string,string>::iterator i = attributes.begin(); i != attributes.end(); i++) {
180 string key = i->first;
183 int length = key.length() + value.length() + 3;
195 *
writer << key.c_str() <<
"=\"" << value.c_str() <<
"\"";
205 int len = s.length();
206 for (
int i = 0; i <
len; i++) {
222 str.append(
""");
227 sprintf(buffer,
"&#%ud", ch);
250 int len = s.length();
251 for (
int i = 0; i <
len; i++) {
std::string normalizeText(std::string s)
void println(std::string text)
void printTag(std::string name)
void printComment(std::string comment)
void closeDoc(bool force=false)
std::string getIndentString() const
void printAttributes(int tagLength)
void referToDTD(std::string name, std::string pid, std::string ref)
const XML_Char const XML_Char int standalone
void openTag(std::string name)
void print(std::string text)
void setIndentString(const std::string &indentString)
const XML_Char int const XML_Char * value
IndentPrintWriter * writer
std::string normalize(std::string s)
void setAttribute(std::string name, char *value)
void openDoc(std::string version="1.0", std::string encoding="", bool standalone=false)
void printPlain(std::string text)
std::string toShowLabel()
void checkNameValid(std::string s)
std::string getAsString()