本文整理汇总了C++中DomNode::to_element方法的典型用法代码示例。如果您正苦于以下问题:C++ DomNode::to_element方法的具体用法?C++ DomNode::to_element怎么用?C++ DomNode::to_element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomNode
的用法示例。
在下文中一共展示了DomNode::to_element方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_next_sibling_element
DomElement DomElement::get_next_sibling_element() const
{
DomNode node = get_next_sibling();
while (!node.is_null() && !node.is_element())
node = node.get_next_sibling();
return node.to_element();
}
示例2: select_string
std::string DomNode::select_string(const DomString &xpath_expression) const
{
DomNode node = select_node(xpath_expression);
if (node.is_element())
return node.to_element().get_text();
else
return node.get_node_value();
}
示例3: get_document_element
DomElement DomDocument::get_document_element()
{
DomNode cur = get_first_child();
while (!cur.is_null())
{
if (cur.is_element())
return cur.to_element();
cur = cur.get_next_sibling();
}
return DomElement();
}
示例4: get_text
std::string DomElement::get_text() const
{
std::string str;
if (has_child_nodes() == false)
return str;
DomNode cur = get_first_child();
while (!cur.is_null())
{
if (cur.is_text() || cur.is_cdata_section())
str.append(cur.get_node_value());
if (cur.is_element())
str.append(cur.to_element().get_text());
cur = cur.get_next_sibling();
}
return str;
}
示例5: load
ProgramObject ProgramObject::load(
GraphicContext &gc,
const std::string &resource_id,
const XMLResourceDocument &resources)
{
ProgramObject program_object(gc);
XMLResourceNode resource = resources.get_resource(resource_id);
DomNode node = resource.get_element().get_first_child();
while (!node.is_null())
{
if (node.is_element())
{
DomElement element = node.to_element();
if (element.get_tag_name() == "shader")
{
ShaderObject shader = ShaderObject::load(gc, element.get_attribute("name"), resources);
program_object.attach(shader);
}
else if (element.get_tag_name() == "bind-attribute")
{
program_object.bind_attribute_location(
StringHelp::text_to_int(element.get_attribute("index")),
element.get_attribute("name"));
}
}
node = node.get_next_sibling();
}
if (!resource.get_element().get_attribute("shader").empty())
{
ShaderObject shader = ShaderObject::load(gc, resource.get_element().get_attribute("shader"), resources);
program_object.attach(shader);
}
if (resource.get_element().get_attribute("link", "true") == "true")
if(!program_object.link())
throw Exception(string_format("Unable to link program object: %1", program_object.get_info_log()));
return program_object;
}
示例6: if
ResourceItem *TexturePacker::load_resource(Canvas &canvas, std::string &resource_id, Resource &resource, ResourceManager &resources)
{
ResourceItem *item = 0;
try
{
std::string type = resource.get_type();
if(type == "sprite")
{
item = load_sprite(canvas, resource_id, resource, resources);
}
else if(type == "image")
{
item = load_image(canvas, resource_id, resource, resources);
}
else
{
throw Exception(string_format("Resourcetype %1 is not supported", type));
}
}
catch(Exception ex)
{
item = new NotSupportedResourceItem(resource, ex.message);
}
// Find resource path by traversing parents
DomElement &dom_element = resource.get_element();
DomNode parent = dom_element.get_parent_node();
while (!parent.is_null())
{
DomElement parent_element = parent.to_element();
std::string parent_name = parent_element.get_attribute("name");
if(parent_name.length() > 0)
item->resource_path = string_format("%1/%2", parent_name, item->resource_path);
parent = parent.get_parent_node();
}
return item;
}
示例7: 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];
}