本文整理汇总了C++中CL_DomNode::to_element方法的典型用法代码示例。如果您正苦于以下问题:C++ CL_DomNode::to_element方法的具体用法?C++ CL_DomNode::to_element怎么用?C++ CL_DomNode::to_element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CL_DomNode
的用法示例。
在下文中一共展示了CL_DomNode::to_element方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_next_sibling_element
CL_DomElement CL_DomElement::get_next_sibling_element() const
{
CL_DomNode node = get_next_sibling();
while (!node.is_null() && !node.is_element())
node = node.get_next_sibling();
return node.to_element();
}
示例2: select_string
CL_String CL_DomNode::select_string(const CL_DomString &xpath_expression) const
{
CL_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
CL_DomElement CL_DomDocument::get_document_element()
{
CL_DomNode cur = get_first_child();
while (!cur.is_null())
{
if (cur.is_element())
return cur.to_element();
cur = cur.get_next_sibling();
}
return CL_DomElement();
}
示例4: get_text
CL_String CL_DomElement::get_text() const
{
CL_String str;
if (has_child_nodes() == false)
return str;
CL_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: if
ResourceItem *TexturePacker::load_resource(CL_GraphicContext &gc, CL_String &resource_id, CL_Resource &resource, CL_ResourceManager &resources)
{
ResourceItem *item = 0;
try
{
CL_String type = resource.get_type();
if(type == "sprite")
{
item = load_sprite(gc, resource_id, resource, resources);
}
else if(type == "image")
{
item = load_image(gc, resource_id, resource, resources);
}
else
{
throw CL_Exception(cl_format("Resourcetype %1 is not supported", type));
}
}
catch(CL_Exception ex)
{
item = new NotSupportedResourceItem(resource, ex.message);
}
// Find resource path by traversing parents
CL_DomElement &dom_element = resource.get_element();
CL_DomNode parent = dom_element.get_parent_node();
while (!parent.is_null())
{
CL_DomElement parent_element = parent.to_element();
CL_String parent_name = parent_element.get_attribute("name");
if(parent_name.length() > 0)
item->resource_path = cl_format("%1/%2", parent_name, item->resource_path);
parent = parent.get_parent_node();
}
return item;
}
示例6: load_css_layout
void CL_GUIComponent::load_css_layout(const CL_String &xml_filename, const CL_String &css_filename)
{
CL_CSSDocument2 css_document;
css_document.add_sheet(css_filename);
CL_File file(xml_filename);
CL_DomDocument dom(file, false);
CL_DomNode cur = dom.get_document_element().get_first_child();
std::vector<CL_CSSLayoutElement> element_stack;
{
CL_DomSelectNode select_node(dom.get_document_element());
impl->css_element.apply_properties(css_document.select(&select_node));
impl->css_element.apply_properties(dom.get_document_element().get_attribute("style"));
impl->css_element.set_col_span(dom.get_document_element().get_attribute_int("colspan", 1));
impl->css_element.set_row_span(dom.get_document_element().get_attribute_int("rowspan", 1));
}
element_stack.push_back(impl->css_element);
while (!cur.is_null())
{
CL_CSSLayoutElement child_css_element;
if (cur.is_element())
{
CL_DomElement cur_element = cur.to_element();
CL_DomSelectNode select_node(cur_element);
child_css_element = element_stack.back().create_element(cur_element.get_tag_name());
child_css_element.apply_properties(css_document.select(&select_node));
child_css_element.apply_properties(cur_element.get_attribute("style"));
child_css_element.set_col_span(cur_element.get_attribute_int("colspan", 1));
child_css_element.set_row_span(cur_element.get_attribute_int("rowspan", 1));
}
else if (cur.is_text())
{
CL_DomText cur_text = cur.to_text();
element_stack.back().create_text(cur_text.get_node_value());
}
CL_DomNode next = cur.get_first_child();
if (next.is_null())
{
next = cur.get_next_sibling();
if (next.is_null())
{
next = cur.get_parent_node();
while (!next.is_null() && next.get_next_sibling().is_null())
next = next.get_parent_node();
if (!next.is_null())
next = next.get_next_sibling();
}
}
else
{
element_stack.push_back(child_css_element);
}
cur = next;
}
CL_GraphicContext gc = get_gc();
impl->css_layout.layout(gc, get_size());
}
示例7: main
int ConsoleProgram::main(const std::vector<CL_String> &args)
{
// Setup clanCore:
CL_SetupCore setup_core;
// Initialize the ClanLib display component
CL_SetupDisplay setup_display;
// Create a console Window if one does not exist:
CL_ConsoleWindow console_window("Console", 80, 600);
try
{
//получение параметра запуска
for (std::vector<CL_String>::const_iterator iter_args = args.begin(); iter_args != args.end(); ++iter_args)
CL_Console::write_line( *iter_args );
//получение имени директории для сохранения
CL_String workDirectoryName;
if (args.size() > 1)
{
//полное имя рабочей директории
workDirectoryName = args[1];
//конвертирование из CP-1251 в UTF-8 имени рабочей директории
workDirectoryName = decode(workDirectoryName);
}
else
{
//получение полного пути к текущему каталогу
workDirectoryName = CL_Directory::get_current();
}
CL_Console::write_line("workDirectoryName: %1", workDirectoryName);
//получение имени последней директории
CL_String locationName = CL_PathHelp::remove_trailing_slash(workDirectoryName);
locationName = CL_PathHelp::get_filename(locationName);
CL_Console::write_line("locationName: %1", locationName);
CL_String tempDir = CL_PathHelp::add_trailing_slash(workDirectoryName) + "temp\\";
CL_DirectoryScanner directoryScanner;
directoryScanner.scan(tempDir, "*.export");
while (directoryScanner.next())
{
//имя обрабатываемого файла
CL_String fileName;
if (directoryScanner.is_directory())
continue;
//получение полного имени файла экспорта
fileName = directoryScanner.get_pathname();
//конвертирование из CP-1251 в UTF-8
fileName = decode(fileName);
CL_Console::write_line("find: %1", fileName);
//открытие XML файла
CL_File fileXML;
bool is_opened = fileXML.open(fileName);
if( !is_opened )
return PrintError( CL_String("Can't open file: ") + fileName );
//Создание объекта DOM парсера
CL_DomDocument document(fileXML);
//получение root узла
CL_DomElement root = document.get_document_element();
if( root.get_local_name() != "resources")
{
CL_Console::write_line("Root name can't be: %1", root.get_local_name().c_str());
return PrintError("");
}
//цикл по потомкам "resources"
for (CL_DomNode cur = root.get_first_child(); !cur.is_null(); cur = cur.get_next_sibling())
{
//загрузка только спрайтов
if (cur.get_node_name() != "sprite")
continue;
CL_DomElement element = cur.to_element();
//проверка на обязательные параметры
if (!element.has_attribute("name"))
return PrintError("Error: can't find parametr \"name\"");
CL_DomString name = element.get_attribute("name");
int x = element.get_attribute_int("x");
int y = element.get_attribute_int("y");
//добавление спрайта
sprites.push_back( S_Sprite(name, CL_Vec2i(x, y) ) );
//цикл по "image" (формирование списка имен файлов)
for (CL_DomNode cur_image = cur.get_first_child(); !cur_image.is_null(); cur_image = cur_image.get_next_sibling())
{
//загрузка только image
if (cur_image.get_node_name() != "image")
continue;
CL_DomElement element_image = cur_image.to_element();
CL_DomString file = element_image.get_attribute("file");
//конвертирование из CP-1251 в UTF-8 имени файла изображения
//.........这里部分代码省略.........
示例8: create_resource
CL_Resource CL_ResourceManager::create_resource(const CL_String &resource_id, const CL_String &type)
{
if (resource_exists(resource_id))
throw CL_Exception(cl_format("Resource %1 already exists", resource_id));
std::vector<CL_String> path_elements = CL_PathHelp::split_basepath(resource_id);
CL_String name = CL_PathHelp::get_filename(resource_id);
// Walk tree as deep as we can get:
CL_DomNode parent = impl->document.get_document_element();
CL_DomNode cur = parent.get_first_child();
std::vector<CL_String>::iterator 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")
{
CL_DomElement element = cur.to_element();
CL_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:
CL_String prefix = parent.get_prefix();
while (path_it != path_elements.end())
{
CL_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:
CL_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] = CL_Resource(resource_node, *this);
return impl->resources[resource_id];
}