Exemplo n.º 1
0
CL_DomString CL_DomNode::find_prefix(const CL_DomString &namespace_uri) const
{
	CL_DomElement cur = to_element();
	while (!cur.is_null())
	{
		CL_DomNamedNodeMap attributes = cur.get_attributes();
		int size = attributes.get_length();
		for (int index = 0; index < size; index++)
		{
			CL_DomNode attribute = attributes.item(index);
			if (attribute.get_prefix() == "xmlns" &&
				attribute.get_node_value() == namespace_uri)
			{
				return attribute.get_local_name();
			}
		}
		cur = cur.get_parent_node().to_element();
	}
	return CL_DomString();
}
Exemplo n.º 2
0
//рекурсивное клонирование XML-элемента
CL_DomElement cloneElement(CL_DomElement &element, CL_DomDocument &doc)
{
	//создаем элемент-клон
	CL_DomElement clone(doc, element.get_tag_name());

	//копируем атрибуты
	CL_DomNamedNodeMap attributes = element.get_attributes();
	unsigned long length = attributes.get_length();
	for (unsigned long i = 0; i < length; ++i)
	{
		CL_DomNode attr = attributes.item(i);
		clone.set_attribute(attr.get_node_name(), attr.get_node_value());
	}

	//рекурсивно копируем дочерние элементы
	for (CL_DomElement child = element.get_first_child_element(); !child.is_null(); child = child.get_next_sibling_element())
		clone.append_child(cloneElement(child, doc));

	//возвращаем клонированный элемент
	return clone;
}