void Configure::writeDictItem(int item) { if (item > DICTNODE_NUM_MAX) return; SpinLock lock(m_cs); XMLElement* dictElement = XMLHandle(m_doc.RootElement()).FirstChildElement("dict").ToElement(); XMLElement* e = util::XMLUtil::Child(dictElement, item); if (e == NULL) { e = m_doc.NewElement("d"); e->SetAttribute("open", m_dictNodes[item].open.c_str()); e->SetAttribute("en", m_dictNodes[item].en); XMLElement* textE = m_doc.NewElement("summary"); textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].summary.c_str())); e->InsertFirstChild(textE); textE = m_doc.NewElement("path"); textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].path.c_str())); e->InsertFirstChild(textE); textE = m_doc.NewElement("name"); textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].name.c_str())); e->InsertFirstChild(textE); textE = m_doc.NewElement("detlan"); textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].detlan.c_str())); e->InsertFirstChild(textE); textE = m_doc.NewElement("srclan"); textE->InsertFirstChild(m_doc.NewText(m_dictNodes[item].srclan.c_str())); e->InsertFirstChild(textE); dictElement->InsertEndChild(e); } else { e->SetAttribute("open", m_dictNodes[item].open.c_str()); e->SetAttribute("en", m_dictNodes[item].en); XMLText* txt = e->FirstChildElement("path")->FirstChild()->ToText(); txt->SetValue(m_dictNodes[item].path.c_str()); txt = e->FirstChildElement("name")->FirstChild()->ToText(); txt->SetValue(m_dictNodes[item].name.c_str()); txt = XMLHandle(e).FirstChildElement("detlan").FirstChild().ToText(); if (txt) txt->SetValue(m_dictNodes[item].detlan.c_str()); txt = XMLHandle(e).FirstChildElement("srclan").FirstChild().ToText(); if (txt) txt->SetValue(m_dictNodes[item].srclan.c_str()); txt = XMLHandle(e).FirstChildElement("summary").FirstChild().ToText(); if (txt) txt->SetValue(m_dictNodes[item].summary.c_str()); } /*printf("writeDictItem(%s): %d, %s -> %s\n", ndname.c_str(), item, m_dictNodes[item].srclan.c_str(), m_dictNodes[item].detlan.c_str());*/ m_dirty = true; }
XMLText* XMLDocument::NewText( const char* str ) { XMLText* text = new (_textPool.Alloc()) XMLText( this ); text->_memPool = &_textPool; text->SetValue( str ); return text; }
void Configure::writeDetLan(const string& lan) { if (m_detLan.compare(lan) != 0) { SpinLock lock(m_cs); m_detLan = lan; XMLText* txt = XMLHandle(m_doc.RootElement()).FirstChildElement("detlan").FirstChild().ToText(); if (txt) { txt->SetValue(lan.c_str()); m_dirty = true; } } }
bool FractalConfiguration::save(string filename) { if(invalidID()) return true; // Check filename and append .xml if(!endsWith(filename, ".xml")) filename += ".xml"; // Create document XMLDocument doc; // Root element XMLElement *root = doc.NewElement("fractal"); root->SetAttribute("id", m_id.c_str()); doc.InsertEndChild(root); // Add properties iterate(); while(true) { if(!next()) break; XMLElement *prop = doc.NewElement("property"); prop->SetAttribute("name", getName().c_str()); XMLText *text = doc.NewText(""); if(isString()) { prop->SetAttribute("type", "string"); text->SetValue(getString().c_str()); } else if(isInt()) { prop->SetAttribute("type", "int"); stringstream ss; ss << getInt(); text->SetValue(ss.str().c_str()); } else if(isDouble()) { prop->SetAttribute("type", "double"); stringstream ss; ss << getDouble(); text->SetValue(ss.str().c_str()); } else if(isBool()) { prop->SetAttribute("type", "bool"); if(getBool()) text->SetValue("1"); else text->SetValue("0"); } prop->InsertEndChild(text); root->InsertEndChild(prop); } // Save to file if(doc.SaveFile(filename.c_str()) != XML_NO_ERROR) { m_last_error = doc.GetErrorStr1(); return true; } resetDirty(); return false; }