本文整理汇总了C++中pugi::xml_node::first_element_by_path方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_node::first_element_by_path方法的具体用法?C++ xml_node::first_element_by_path怎么用?C++ xml_node::first_element_by_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pugi::xml_node
的用法示例。
在下文中一共展示了xml_node::first_element_by_path方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildXmlNode
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;
}
示例2: getNodeFromPath
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());
}
}
示例3: T
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;
}