Ejemplo n.º 1
0
	void DomElement::remove_attribute(const DomString &name)
	{
		if (impl)
		{
			DomNamedNodeMap attributes = get_attributes();
			attributes.remove_named_item(name);
		}
	}
Ejemplo n.º 2
0
	DomAttr DomElement::get_attribute_node(const DomString &name) const
	{
		if (impl)
		{
			DomNamedNodeMap attributes = get_attributes();
			DomAttr attribute = attributes.get_named_item(name).to_attr();
			return attribute;
		}
		return DomAttr();
	}
Ejemplo n.º 3
0
	void DomElement::remove_attribute_ns(
		const DomString &namespace_uri,
		const DomString &local_name)
	{
		if (impl)
		{
			DomNamedNodeMap attributes = get_attributes();
			attributes.remove_named_item_ns(namespace_uri, local_name);
		}
	}
Ejemplo n.º 4
0
	DomAttr DomElement::get_attribute_node_ns(
		const DomString &namespace_uri,
		const DomString &local_name) const
	{
		if (impl)
		{
			DomNamedNodeMap attributes = get_attributes();
			DomAttr attribute = attributes.get_named_item_ns(namespace_uri, local_name).to_attr();
			return attribute;
		}
		return DomAttr();
	}
Ejemplo n.º 5
0
	void DomElement::set_attribute(const DomString &name, const DomString &value)
	{
		if (impl)
		{
			DomNamedNodeMap attributes = get_attributes();
			DomAttr attribute = attributes.get_named_item(name).to_attr();
			if (attribute.is_attr())
			{
				attribute.set_node_value(value);
			}
			else
			{
				attribute = get_owner_document().create_attribute(name);
				attribute.set_node_value(value);
				attributes.set_named_item(attribute);
			}
		}
	}
Ejemplo n.º 6
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();
	}
Ejemplo n.º 7
0
	void DomDocument::save(IODevice &output, bool insert_whitespace)
	{
		XMLWriter writer(output);
		writer.set_insert_whitespace(insert_whitespace);

		std::vector<DomNode> node_stack;
		DomNode cur_node = get_first_child();
		while (!cur_node.is_null())
		{
			// Create opening node:
			XMLToken opening_node;
			opening_node.type = (XMLToken::TokenType) cur_node.get_node_type();
			opening_node.variant = cur_node.has_child_nodes() ? XMLToken::BEGIN : XMLToken::SINGLE;
			opening_node.name = cur_node.get_node_name();
			opening_node.value = cur_node.get_node_value();
			if (cur_node.is_element())
			{
				DomNamedNodeMap attributes = cur_node.get_attributes();
				int length = attributes.get_length();
				for (int i = 0; i < length; ++i)
				{
					DomAttr attribute = attributes.item(i).to_attr();
					opening_node.attributes.push_back(
						XMLToken::Attribute(
						attribute.get_name(),
						attribute.get_value()));
				}
			}
			writer.write(opening_node);

			// Create any possible child nodes:
			if (cur_node.has_child_nodes())
			{
				node_stack.push_back(cur_node);
				cur_node = cur_node.get_first_child();
				continue;
			}

			// Create closing nodes until we reach next opening node in tree:
			while (true)
			{
				if (cur_node.has_child_nodes())
				{
					XMLToken closing_node;
					closing_node.type = (XMLToken::TokenType) cur_node.get_node_type();
					closing_node.name = cur_node.get_node_name();
					closing_node.variant = XMLToken::END;
					writer.write(closing_node);
				}

				cur_node = cur_node.get_next_sibling();
				if (!cur_node.is_null())
					break;
				if (node_stack.empty())
					break;

				cur_node = node_stack.back();
				node_stack.pop_back();
			}
		}
	}