Exemplo n.º 1
0
void CL_ResourceManager::destroy_resource(const CL_String &resource_id)
{
	std::map<CL_String, CL_Resource>::iterator it;
	it = impl->resources.find(resource_id);
	if (it == impl->resources.end())
		return;
	CL_DomNode cur = it->second.get_element();
	impl->resources.erase(it);
	CL_DomNode parent = cur.get_parent_node();
	while (!parent.is_null())
	{
		parent.remove_child(cur);
		if (parent.has_child_nodes())
			break;
		cur = parent;
		parent = parent.get_parent_node();
	}
}
Exemplo n.º 2
0
std::vector<CL_DomNode> CL_DomDocument::load(
	CL_IODevice &input,
	bool eat_whitespace,
	CL_DomNode insert_point)
{
	clear_all();

	CL_XMLTokenizer tokenizer(input);
	tokenizer.set_eat_whitespace(eat_whitespace);

	if (insert_point.is_element() == false)
		insert_point = *this;
		
	std::vector<CL_DomNode> node_stack;
	node_stack.push_back(insert_point);

	std::vector<CL_DomNode> result;
	
	try
	{
		CL_XMLToken cur_token;
		tokenizer.next(&cur_token);
		while (cur_token.type != CL_XMLToken::NULL_TOKEN)
		{
			switch (cur_token.type)
			{
			case CL_XMLToken::TEXT_TOKEN:
				node_stack.back().append_child(create_text_node(cur_token.value));
				if (node_stack.back() == insert_point)
					result.push_back(node_stack.back().get_last_child());
				break;

			case CL_XMLToken::CDATA_SECTION_TOKEN:
				node_stack.back().append_child(create_cdata_section(cur_token.value));
				if (node_stack.back() == insert_point)
					result.push_back(node_stack.back().get_last_child());
				break;

			case CL_XMLToken::ELEMENT_TOKEN:
				if (cur_token.variant != CL_XMLToken::END)
				{
					CL_DomString namespace_uri = CL_DomDocument_Generic::find_namespace_uri(cur_token.name, cur_token, node_stack.back());
					CL_DomElement element = create_element_ns(namespace_uri, cur_token.name);
					node_stack.back().append_child(element);
					if (node_stack.back() == insert_point)
						result.push_back(node_stack.back().get_last_child());

					int size = (int) cur_token.attributes.size();
					for (int i=0; i<size; i++)
					{
						CL_XMLToken::Attribute &attribute = cur_token.attributes[i];
						CL_DomString attribute_namespace_uri = CL_DomDocument_Generic::find_namespace_uri(attribute.first, cur_token, node_stack.back());
						element.set_attribute_ns(
							attribute_namespace_uri,
							attribute.first,
							attribute.second);
					}
				
					if (cur_token.variant == CL_XMLToken::BEGIN)
						node_stack.push_back(element);
				}
				else
				{
					node_stack.pop_back();
					if (node_stack.empty()) throw CL_Exception("Malformed XML tree!");
				}
				break;

			case CL_XMLToken::NULL_TOKEN: 
				break;

			case CL_XMLToken::ENTITY_REFERENCE_TOKEN: 
				break;

			case CL_XMLToken::ENTITY_TOKEN: 
				break;
			
			case CL_XMLToken::COMMENT_TOKEN:
				break;

			case CL_XMLToken::DOCUMENT_TYPE_TOKEN:
				break;

			case CL_XMLToken::NOTATION_TOKEN:
				break;

			case CL_XMLToken::PROCESSING_INSTRUCTION_TOKEN:
				break;
			}		

			tokenizer.next(&cur_token);
		}
	}
	catch (const CL_Exception& e)
	{
		for (std::vector<CL_DomNode>::size_type i = 0; i < result.size(); i++)
		{
			insert_point.remove_child(result[i]);
		}
		throw;
	}
	return result;
}