本文整理汇总了C++中DomElement::get_first_child方法的典型用法代码示例。如果您正苦于以下问题:C++ DomElement::get_first_child方法的具体用法?C++ DomElement::get_first_child怎么用?C++ DomElement::get_first_child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomElement
的用法示例。
在下文中一共展示了DomElement::get_first_child方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_child_string_ns
void DomElement::set_child_string_ns(const DomString &namespace_uri, const DomString &qualified_name, const DomString &value)
{
DomString local_name;
DomString::size_type pos = qualified_name.find(L':');
if (pos != DomString::npos)
local_name = qualified_name.substr(pos + 1);
else
local_name = qualified_name;
DomElement element = named_item_ns(namespace_uri, local_name).to_element();
if (element.is_null())
{
element = get_owner_document().create_element_ns(namespace_uri, qualified_name);
append_child(element);
}
DomText dom_text = get_owner_document().create_text_node(value);
if (element.get_first_child().is_text())
{
DomNode temp_domnode = element.get_first_child();
replace_child(dom_text, temp_domnode);
}
else
{
element.append_child(dom_text);
}
}
示例2: get_child_string_ns
DomString DomElement::get_child_string_ns(const DomString &namespace_uri, const DomString &local_name, const DomString &default_value) const
{
DomElement element = named_item_ns(namespace_uri, local_name).to_element();
if (!element.is_null() && element.get_first_child().is_text())
return element.get_first_child().to_text().get_node_value();
else
return default_value;
}
示例3: set_child_string
void DomElement::set_child_string(const DomString &name, const DomString &value)
{
DomElement element = named_item(name).to_element();
if (element.is_null())
{
element = get_owner_document().create_element(name);
append_child(element);
}
while (!element.get_first_child().is_null())
{
DomNode my_child = element.get_first_child();
element.remove_child(my_child);
}
DomText dom_text = get_owner_document().create_text_node(value);
element.append_child(dom_text);
}
示例4: load
void XMLResourceDocument::load(IODevice file, const std::string &base_path, const FileSystem &fs)
{
DomDocument new_document;
new_document.load(file);
// Check if loaded document uses namespaces and if its a clanlib resources xml document:
DomElement doc_element = new_document.get_document_element();
if (doc_element.get_namespace_uri().empty() && doc_element.get_local_name() == "resources")
{
impl->ns_resources = std::string();
}
else if (doc_element.get_namespace_uri() == "http://clanlib.org/xmlns/resources-1.0")
{
if (doc_element.get_local_name() != "resources")
throw Exception("ClanLib resource documents must begin with a resources element.");
impl->ns_resources = "http://clanlib.org/xmlns/resources-1.0";
}
else
{
throw Exception("XML document is not a ClanLib resources document.");
}
impl->document = new_document;
impl->fs = fs;
impl->base_path = base_path;
impl->resources.clear();
std::vector<std::string> section_stack;
std::vector<DomNode> nodes_stack;
section_stack.push_back(std::string());
nodes_stack.push_back(doc_element.get_first_child());
while (!nodes_stack.empty())
{
if (nodes_stack.back().is_element())
{
DomElement element = nodes_stack.back().to_element();
if (element.get_namespace_uri() == impl->ns_resources && element.get_local_name() == "section")
{
std::string section_name = element.get_attribute_ns(impl->ns_resources, "name");
section_stack.push_back(section_stack.back() + PathHelp::add_trailing_slash(section_name, PathHelp::path_type_virtual));
nodes_stack.push_back(element.get_first_child());
continue;
}
else if (element.has_attribute_ns(impl->ns_resources, "name"))
{
std::string resource_name = element.get_attribute_ns(impl->ns_resources, "name");
std::string resource_id = section_stack.back() + resource_name;
impl->resources[resource_id] = XMLResourceNode(element, *this);
}
}
nodes_stack.back() = nodes_stack.back().get_next_sibling();
while (nodes_stack.back().is_null())
{
nodes_stack.pop_back();
section_stack.pop_back();
if (nodes_stack.empty())
break;
nodes_stack.back() = nodes_stack.back().get_next_sibling();
}
}
}