Exemplo n.º 1
0
void CAppRegistry::Save()
{
  CSingleLock lock(m_lock);

  TiXmlElement rootElement("registry");
  CStdString key;
  for (RegistryDataIterator keyIter = m_data.begin(); keyIter != m_data.end(); keyIter++)
  {
    key = keyIter->first;
    RegistryValue& values = keyIter->second;
    
    for (size_t i = 0; i < values.size(); i++)
    {
      TiXmlElement valueElement("value");
      valueElement.SetAttribute("id", key.c_str());
      
      TiXmlText valueText(values[i]);
      valueElement.InsertEndChild(valueText);
      
      rootElement.InsertEndChild(valueElement);
    }
  }

  TiXmlDocument xmlDoc;
  xmlDoc.InsertEndChild(rootElement);

  ::CreateDirectory(m_dir, NULL);
  
  xmlDoc.SaveFile(m_fileName);
}
Exemplo n.º 2
0
std::shared_ptr<XMLElement> FormSerializer::fieldToXML(std::shared_ptr<FormField> field, bool withTypeAttribute) const {
    std::shared_ptr<XMLElement> fieldElement(new XMLElement("field"));
    if (!field->getName().empty()) {
        fieldElement->setAttribute("var", field->getName());
    }
    if (!field->getLabel().empty()) {
        fieldElement->setAttribute("label", field->getLabel());
    }
    if (field->getRequired()) {
        fieldElement->addNode(std::make_shared<XMLElement>("required"));
    }
    if (!field->getDescription().empty()) {
        std::shared_ptr<XMLElement> descriptionElement(new XMLElement("desc"));
        descriptionElement->addNode(std::make_shared<XMLTextNode>(field->getDescription()));
        fieldElement->addNode(descriptionElement);
    }

    // Set the value and type
    std::string fieldType;
    switch (field->getType()) {
        case FormField::UnknownType: fieldType = ""; break;
        case FormField::BooleanType: fieldType = "boolean"; break;
        case FormField::FixedType: fieldType = "fixed"; break;
        case FormField::HiddenType: fieldType = "hidden"; break;
        case FormField::ListSingleType: fieldType = "list-single"; break;
        case FormField::TextMultiType: fieldType = "text-multi"; break;
        case FormField::TextPrivateType: fieldType = "text-private"; break;
        case FormField::TextSingleType: fieldType = "text-single"; break;
        case FormField::JIDSingleType: fieldType = "jid-single"; break;
        case FormField::JIDMultiType: fieldType = "jid-multi"; break;
        case FormField::ListMultiType: fieldType = "list-multi"; break;
    }
    if (!fieldType.empty() && withTypeAttribute) {
        fieldElement->setAttribute("type", fieldType);
    }
    for (const auto& value : field->getValues()) {
        std::shared_ptr<XMLElement> valueElement = std::make_shared<XMLElement>("value");
        valueElement->addNode(std::make_shared<XMLTextNode>(value));
        fieldElement->addNode(valueElement);
    }

    for (const auto& option : field->getOptions()) {
        std::shared_ptr<XMLElement> optionElement(new XMLElement("option"));
        if (!option.label.empty()) {
            optionElement->setAttribute("label", option.label);
        }

        std::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
        valueElement->addNode(XMLTextNode::create(option.value));
        optionElement->addNode(valueElement);
        fieldElement->addNode(optionElement);
    }
    return fieldElement;
}