当前位置: 首页>>代码示例>>C++>>正文


C++ CL_DomElement::get_local_name方法代码示例

本文整理汇总了C++中CL_DomElement::get_local_name方法的典型用法代码示例。如果您正苦于以下问题:C++ CL_DomElement::get_local_name方法的具体用法?C++ CL_DomElement::get_local_name怎么用?C++ CL_DomElement::get_local_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CL_DomElement的用法示例。


在下文中一共展示了CL_DomElement::get_local_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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 имени файла изображения
//.........这里部分代码省略.........
开发者ID:ermachkov,项目名称:bmgui,代码行数:101,代码来源:main.cpp

示例2: load

void CL_ResourceManager::load(CL_IODevice file, CL_VirtualDirectory directory)
{
	CL_DomDocument new_document;
	new_document.load(file);

	// Check if loaded document uses namespaces and if its a clanlib resources xml document:
	CL_DomElement doc_element = new_document.get_document_element();
	if (doc_element.get_namespace_uri().empty() && doc_element.get_local_name() == "resources")
	{
		impl->ns_resources = CL_String();
	}
	else if (doc_element.get_namespace_uri() == "http://clanlib.org/xmlns/resources-1.0")
	{
		if (doc_element.get_local_name() != "resources")
			throw CL_Exception("ClanLib resource documents must begin with a resources element.");

		impl->ns_resources = "http://clanlib.org/xmlns/resources-1.0";
	}
	else
	{
		throw CL_Exception("XML document is not a ClanLib resources document.");
	}

	impl->document = new_document;
	impl->directory = directory;
	impl->resources.clear();

	std::vector<CL_String> section_stack;
	std::vector<CL_DomNode> nodes_stack;
	section_stack.push_back(CL_String());
	nodes_stack.push_back(doc_element.get_first_child());
	while (!nodes_stack.empty())
	{
		if (nodes_stack.back().is_element())
		{
			CL_DomElement element = nodes_stack.back().to_element();
			if (element.get_namespace_uri() == impl->ns_resources && element.get_local_name() == "section")
			{
				CL_String section_name = element.get_attribute_ns(impl->ns_resources, "name");
				section_stack.push_back(section_stack.back() + CL_PathHelp::add_trailing_slash(section_name, CL_PathHelp::path_type_virtual));
				nodes_stack.push_back(element.get_first_child());
				continue;
			}
			else if (element.has_attribute_ns(impl->ns_resources, "name"))
			{
				CL_String resource_name = element.get_attribute_ns(impl->ns_resources, "name");
				CL_String resource_id = section_stack.back() + resource_name;
				impl->resources[resource_id] = CL_Resource(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();
		}
	}
}
开发者ID:animehunter,项目名称:clanlib-2.3,代码行数:63,代码来源:resource_manager.cpp


注:本文中的CL_DomElement::get_local_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。