Esempio n. 1
0
pugi::xml_node Config::buildXmlNode(pugi::xml_node& rootNode, const UnicodeString& path) const {
    unsigned int indexOfSlash = path.lastIndexOf('/');
    UnicodeString parentPath(path, 0, indexOfSlash);
    UnicodeString selfName(path, indexOfSlash + 1);

    //LOGARG_DEBUG(LOGTYPE_MAIN, "buildxmlnode parentPath: %s selfName: %s", StringConverter::toUtf8String(parentPath).c_str(), StringConverter::toUtf8String(selfName).c_str());

    pugi::xml_node parentNode;
    if (indexOfSlash == 0) {
        parentNode = rootNode;
    }

    if (!parentNode) {
        std::string utf8ParentPath = StringConverter::toUtf8String(parentPath);
        parentNode = rootNode.first_element_by_path(utf8ParentPath.c_str(), '/');
    }

    if (!parentNode) {
        parentNode = buildXmlNode(rootNode, parentPath);
    }

    pugi::xml_node ret = parentNode.append_child(pugi::node_element);
    ret.set_name(StringConverter::toUtf8String(selfName).c_str());

    return ret;
}
Esempio n. 2
0
pugi::xml_node XMLBuilder::getNodeFromPath(const pugi::xml_node& i_parrentNode,
                                           const std::string& i_path) {
  pugi::xml_node childNode =
      i_parrentNode.first_element_by_path(i_path.c_str());
  if (childNode) {
    return childNode;
  } else {
    LOG_ERROR("Could not find a child node from: "
              << i_path << " starting at node: " << i_parrentNode.name());
  }
}
Esempio n. 3
0
std::vector<T> XMLBuilder::getList(const pugi::xml_node& i_node,
                                   const std::string& i_path,
                                   const int& i_expectedNumberOfValues,
                                   T (*f)(const pugi::xml_text&)) const {
  std::vector<T> list;
  pugi::xml_node parrentNode = i_node.first_element_by_path(i_path.c_str());
  for (pugi::xml_node node = parrentNode.first_child();
       node;
       node = node.next_sibling()) {
    list.push_back((*f)(node.text()));
  }
  if (static_cast<int>(list.size()) != i_expectedNumberOfValues) {
    LOG_ERROR("Number of expected values: " << i_expectedNumberOfValues <<
              " is not equal to: " << list.size());
  }
  return list;
}