int CzXmlNode::SaveAttributes(CzFile* file) { for (CzXmlAttributeList::iterator i = Attributes.begin(); i != Attributes.end(); ++i) { CzString out; out.allocString(512); out = " "; out += (*i)->Name.c_str(); out += "=\""; out += (*i)->Value.c_str(); out += "\""; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; } return 0; }
int CzXmlNode::SaveTree(CzFile* file, int level) { int err = 0; CzString out; out.allocString(256); for (int t = 0; t < level; t++) out += "\t"; out += "<"; out += Name; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; err = SaveAttributes(file); if (err < 0) return err; if (HasValue) { if (Value.getLength() == 0) out = " />\n"; else { out = ">"; out += Value.c_str(); } out += "</"; out += Name.c_str(); out += ">\n"; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; } else { if (Children.size() == 0) { out = " />\n"; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; } else { out = ">\n"; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; for (CzXmlNodeList::iterator i = Children.begin(); i != Children.end(); ++i) { err = (*i)->SaveTree(file, level + 1); if (err < 0) return err; } for (int t = 0; t < level; t++) { out = "\t"; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; } out = "</"; out += Name.c_str(); out += ">\n"; if (!file->Write((void*)out.c_str(), out.getLength())) return -1; } } return 0; }