62 nspStack[3] =
"http://www.w3.org/XML/1998/namespace";
66 if (encoding.find(
"utf",0)!=std::string::npos)
73 XmlSerializer::check(
bool close)
80 if (indent.size() <= depth) {
81 indent.resize(depth + 4);
83 indent[depth] = indent[depth - 1];
85 for (
int i = nspCounts[depth - 1];
91 if (
""!=nspStack[i * 2]) {
93 writer<<nspStack[i * 2];
95 else if (
getNamespace() !=
"" && nspStack[i * 2 + 1]!=
"")
96 exception(
"Cannot set default namespace for elements in no namespace");
98 writeEscaped(nspStack[i * 2 + 1],
'"');
102 if (nspCounts.size() <= depth + 1) {
103 nspCounts.resize(depth + 8);
106 nspCounts[depth + 1] = nspCounts[depth];
109 writer<<(close ?
" />" :
">");
113 XmlSerializer::writeEscaped(std::string s,
int quot)
116 for (
size_t i = 0; i < s.length(); i++) {
117 unsigned char c = s[i];
125 writer<<
"&#"+((int) c)+
';';
139 writer<<(c ==
'"' ?
""" :
"'");
146 if (c >=
' ' && c !=
'@' && (c < 127 || unicode))
149 writer<<
"&#" << ((int) c) <<
";";
167 elementStack[depth * 3 - 3],
168 elementStack[depth * 3 - 1]);
185 return (
"http://xmlpull.org/v1/doc/features.html#indent-output" == name)
203 for (
int i = nspCounts[depth + 1] * 2 - 2;
207 if (nspStack[i + 1] == ns
208 && (includeDefault || nspStack[i]!=
"")) {
209 std::string cand = nspStack[i];
211 j < nspCounts[depth + 1] * 2;
213 if (nspStack[j]==cand) {
232 prefix =
"n" + (auto_++);
233 for (
int i = nspCounts[depth + 1] * 2 - 2;
236 if (prefix==nspStack[i]) {
242 while (prefix ==
"");
261 if (
"http://xmlpull.org/v1/doc/features.html#indent-output"==name) {
262 indent[depth] = value;
265 exception(
"Unsupported Feature");
272 std::string defined =
getPrefix(nsp,
true,
false);
279 int pos = (nspCounts[depth + 1]++) << 1;
281 if (nspStack.size() < pos + 1) {
282 nspStack.resize(nspStack.size() + 16);
285 nspStack[pos++] = prefix;
293 writer<<
"<?xml version='1.0' ";
295 if (encoding !=
"") {
296 this->encoding = enc;
297 if (encoding.find(
"utf",0)!=std::string::npos)
301 if (encoding !=
"") {
302 writer<<
"encoding='";
307 writer<<
"standalone='";
308 writer<<(standalone ?
"yes" :
"no");
323 for (
int i = 0; i < depth; i++)
328 if (elementStack.size() < esp + 3) {
329 elementStack.resize(elementStack.size() + 16);
338 for (
int i = nspCounts[depth];
339 i < nspCounts[depth + 1];
342 if (nspStack[i * 2]==
"" && nspStack[i * 2 + 1]!=
"") {
343 exception(
"Cannot set default namespace for elements in no namespace");
348 elementStack[esp++] = nsp;
349 elementStack[esp++] = prefix;
350 elementStack[esp] = name;
370 exception(
"illegal position for attribute");
380 std::string prefix =(nsp==
"")?
"":
getPrefix(nsp,
false,
true);
405 char q = value.find(
'"') == std::string::npos ?
'"' :
'\'';
407 writeEscaped(value, q);
429 && elementStack[depth * 3] !=
"")
431 && nsp!=elementStack[depth * 3])
432 || elementStack[depth * 3 + 2] != name)
434 exception(
"</{"+nsp+
"}"+name+
"> does not match start");
441 if (indent[depth + 1]) {
443 for (
int i = 0; i < depth; i++)
448 std::string prefix = elementStack[depth * 3 + 1];
457 nspCounts[depth + 1] = nspCounts[depth]; 463 XmlSerializer::getNamespace() 465 return getDepth() == 0 ? "" : elementStack[getDepth() * 3 - 3]; 469 XmlSerializer::getName() 471 return getDepth() == 0 ? "" : elementStack[getDepth() * 3 - 1]; 475 XmlSerializer::getDepth() { 476 return pending ? depth + 1 : depth; 480 XmlSerializer::text(std::string txt){ 482 indent[depth] = false; 483 writeEscaped(txt, -1); 488 XmlSerializer::text(std::string txt, int start, int len) 490 text(txt.substr(start, len)); 495 XmlSerializer::cdsect(std::string data) 504 XmlSerializer::comment(std::string comment) { 512 XmlSerializer::processingInstruction(std::string pi) 521 XmlSerializer::exception (std::string desc) 523 XmlPullParserException e (desc,elementStack.front(),0,0); void ignorableWhitespace(std::string s)
XmlSerializer & attribute(std::string nsp, std::string name, std::string value)
void startDocument(std::string encoding, bool standalone)
XmlSerializer & endTag(std::string nsp, std::string name)
std::string getPrefix(std::string nsp, bool create)
XmlSerializer & text(std::string txt)
bool getFeature(std::string name)
XmlSerializer & startTag(std::string nsp, std::string name)
XmlSerializer(std::ostream &os, std::string encoding="utf")
void docdecl(std::string dd)
void entityRef(std::string name)
void setPrefix(std::string prefix, std::string nsp)
void setFeature(std::string name, bool value)
std::string getNamespace()