本文整理汇总了C++中DomNode::append_child方法的典型用法代码示例。如果您正苦于以下问题:C++ DomNode::append_child方法的具体用法?C++ DomNode::append_child怎么用?C++ DomNode::append_child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomNode
的用法示例。
在下文中一共展示了DomNode::append_child方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create_resource
XMLResourceNode XMLResourceDocument::create_resource(const std::string &resource_id, const std::string &type)
{
if (resource_exists(resource_id))
throw Exception(string_format("Resource %1 already exists", resource_id));
std::vector<std::string> path_elements = PathHelp::split_basepath(resource_id);
std::string name = PathHelp::get_filename(resource_id);
// Walk tree as deep as we can get:
DomNode parent = impl->document.get_document_element();
DomNode cur = parent.get_first_child();
auto path_it = path_elements.begin();
while (!cur.is_null() && path_it != path_elements.end())
{
if (cur.is_element() &&
cur.get_namespace_uri() == impl->ns_resources &&
cur.get_local_name() == "section")
{
DomElement element = cur.to_element();
std::string name = element.get_attribute_ns(impl->ns_resources, "name");
if (name == *path_it)
{
++path_it;
parent = cur;
cur = cur.get_first_child();
continue;
}
}
cur = cur.get_next_sibling();
}
// Create any missing parent nodes:
std::string prefix = parent.get_prefix();
while (path_it != path_elements.end())
{
DomElement section;
if (prefix.empty())
{
section = impl->document.create_element_ns( impl->ns_resources, (*path_it) );
}
else
{
section = impl->document.create_element_ns( impl->ns_resources,(prefix + ":" + *path_it));
}
parent.append_child(section);
parent = section;
++path_it;
}
// Create node:
DomElement resource_node;
if (prefix.empty())
{
resource_node = impl->document.create_element_ns( impl->ns_resources, (type));
}
else
{
resource_node = impl->document.create_element_ns( impl->ns_resources,(prefix + ":" + type));
}
resource_node.set_attribute_ns(
impl->ns_resources,
prefix.empty() ? "name" : (prefix + ":name"),
name);
parent.append_child(resource_node);
// Create resource:
impl->resources[resource_id] = XMLResourceNode(resource_node, *this);
return impl->resources[resource_id];
}