Пример #1
0
	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();
	}
Пример #2
0
	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;
	}
Пример #3
0
	DomString DomNode::find_prefix(const DomString &namespace_uri) const
	{
		DomElement cur = to_element();
		while (!cur.is_null())
		{
			DomNamedNodeMap attributes = cur.get_attributes();
			int size = attributes.get_length();
			for (int index = 0; index < size; index++)
			{
				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 DomString();
	}
Пример #4
0
	DomNode DomDocument::import_node(const DomNode &node, bool deep)
	{
		DomNode imported_node;
		switch (node.get_node_type())
		{
		case NULL_NODE:
			return imported_node;
		case ELEMENT_NODE:
			imported_node = create_element_ns(node.get_namespace_uri(), node.get_node_name());
			break;
		case ATTRIBUTE_NODE:
			imported_node = create_attribute_ns(node.get_namespace_uri(), node.get_node_name());
			imported_node.set_node_value(node.get_node_value());
			break;
		case TEXT_NODE:
			imported_node = create_text_node(node.get_node_value());
			break;
		case CDATA_SECTION_NODE:
			imported_node = create_cdata_section(node.get_node_value());
			break;
		case ENTITY_REFERENCE_NODE:
			imported_node = create_entity_reference(node.get_node_name());
			break;
		case ENTITY_NODE:
			return imported_node;
		case PROCESSING_INSTRUCTION_NODE:
			imported_node = create_processing_instruction(node.to_processing_instruction().get_target(), node.to_processing_instruction().get_data());
			break;
		case COMMENT_NODE:
			imported_node = create_comment(node.get_node_value());
			break;
		case DOCUMENT_NODE:
			imported_node = create_document_fragment();
			break;
		case DOCUMENT_TYPE_NODE:
			return imported_node;
		case DOCUMENT_FRAGMENT_NODE:
			imported_node = create_document_fragment();
			break;
		case NOTATION_NODE:
			return imported_node;
		}

		if (node.is_element())
		{
			DomElement import_element = imported_node.to_element();
			DomNamedNodeMap node_attributes = node.get_attributes();
			int size = node_attributes.get_length();
			for (int index = 0; index < size; index++)
			{
				DomNode attr = node_attributes.item(index);
				import_element.set_attribute_node_ns(import_node(attr, deep).to_attr());
			}
		}

		if (deep)
		{
			DomNode cur = node.get_first_child();
			while (!cur.is_null())
			{
				imported_node.append_child(import_node(cur, true));
				cur = cur.get_next_sibling();
			}
		}

		return imported_node;
	}