DomNode DomNamedNodeMap::get_named_item_ns( const DomString &namespace_uri, const DomString &local_name) const { if (!impl) return DomNode(); DomDocument_Impl *doc_impl = (DomDocument_Impl *) impl->owner_document.lock().get(); const DomTreeNode *tree_node = impl->get_tree_node(); unsigned int cur_index = tree_node->first_attribute; const DomTreeNode *cur_attribute = tree_node->get_first_attribute(doc_impl); while (cur_attribute) { std::string lname = cur_attribute->get_node_name(); std::string::size_type lpos = lname.find_first_of(':'); if (lpos != std::string::npos) lname = lname.substr(lpos + 1); if (cur_attribute->get_namespace_uri() == namespace_uri && lname == local_name) { DomNode_Impl *dom_node = doc_impl->allocate_dom_node(); dom_node->node_index = cur_index; return DomNode(std::shared_ptr<DomNode_Impl>(dom_node, DomDocument_Impl::NodeDeleter(doc_impl))); } cur_index = cur_attribute->next_sibling; cur_attribute = cur_attribute->get_next_sibling(doc_impl); } return DomNode(); }
DomNode DomNamedNodeMap::remove_named_item(const DomString &name) { if (!impl) return DomNode(); DomDocument_Impl *doc_impl = (DomDocument_Impl *) impl->owner_document.lock().get(); DomTreeNode *tree_node = impl->get_tree_node(); unsigned int cur_index = tree_node->first_attribute; unsigned int last_index = cl_null_node_index; DomTreeNode *cur_attribute = tree_node->get_first_attribute(doc_impl); while (cur_attribute) { if (cur_attribute->get_node_name() == name) { if (cur_attribute->previous_sibling == cl_null_node_index) tree_node->first_attribute = cur_attribute->next_sibling; else cur_attribute->get_previous_sibling(doc_impl)->next_sibling = cur_attribute->next_sibling; if (cur_attribute->next_sibling != cl_null_node_index) cur_attribute->get_next_sibling(doc_impl)->previous_sibling = cur_attribute->previous_sibling; cur_attribute->parent = cl_null_node_index; cur_attribute->previous_sibling = cl_null_node_index; cur_attribute->next_sibling = cl_null_node_index; DomNode_Impl *dom_node = doc_impl->allocate_dom_node(); dom_node->node_index = cur_index; return DomNode(std::shared_ptr<DomNode_Impl>(dom_node, DomDocument_Impl::NodeDeleter(doc_impl))); } last_index = cur_index; cur_index = cur_attribute->next_sibling; cur_attribute = cur_attribute->get_next_sibling(doc_impl); } return DomNode(); }
DomNode DomNode::get_next_sibling() const { if (impl) { const DomTreeNode *tree_node = impl->get_tree_node(); if (tree_node->next_sibling != cl_null_node_index) { DomDocument_Impl *doc_impl = (DomDocument_Impl *)impl->owner_document.lock().get(); DomNode_Impl *dom_node = doc_impl->allocate_dom_node(); dom_node->node_index = tree_node->next_sibling; return DomNode(std::shared_ptr<DomNode_Impl>(dom_node, DomDocument_Impl::NodeDeleter(doc_impl))); } } return DomNode(); }
DomNode DomNode::remove_child(DomNode &old_child) { if (impl && old_child.impl) { DomDocument_Impl *doc_impl = (DomDocument_Impl *)impl->owner_document.lock().get(); DomTreeNode *tree_node = impl->get_tree_node(); DomTreeNode *old_tree_node = old_child.impl->get_tree_node(); unsigned int prev_index = old_tree_node->previous_sibling; unsigned int next_index = old_tree_node->next_sibling; DomTreeNode *prev = old_tree_node->get_previous_sibling(doc_impl); DomTreeNode *next = old_tree_node->get_next_sibling(doc_impl); if (next) next->previous_sibling = prev_index; if (prev) prev->next_sibling = next_index; if (tree_node->first_child == old_child.impl->node_index) tree_node->first_child = next_index; if (tree_node->last_child == old_child.impl->node_index) tree_node->last_child = prev_index; old_tree_node->previous_sibling = cl_null_node_index; old_tree_node->next_sibling = cl_null_node_index; old_tree_node->parent = cl_null_node_index; } return DomNode(); }
DomNode DomNode::insert_before(DomNode &new_child, DomNode &ref_child) { if (!ref_child.impl) { append_child(new_child); return new_child; } if (impl && new_child.impl && ref_child.impl) { DomDocument_Impl *doc_impl = (DomDocument_Impl *)impl->owner_document.lock().get(); DomTreeNode *tree_node = impl->get_tree_node(); DomTreeNode *new_tree_node = new_child.impl->get_tree_node(); DomTreeNode *ref_tree_node = ref_child.impl->get_tree_node(); new_tree_node->previous_sibling = ref_tree_node->previous_sibling; new_tree_node->next_sibling = ref_child.impl->node_index; ref_tree_node->previous_sibling = new_child.impl->node_index; if (new_tree_node->previous_sibling != cl_null_node_index) new_tree_node->get_previous_sibling(doc_impl)->next_sibling = new_child.impl->node_index; if (tree_node->first_child == ref_child.impl->node_index) tree_node->first_child = new_child.impl->node_index; new_tree_node->parent = impl->node_index; return new_child; } return DomNode(); }
DomNode DomNamedNodeMap::set_named_item_ns(const DomNode &node) { if (!impl) return DomNode(); DomDocument_Impl *doc_impl = (DomDocument_Impl *) impl->owner_document.lock().get(); DomString namespace_uri = node.get_namespace_uri(); DomString local_name = node.get_local_name(); DomTreeNode *new_tree_node = (DomTreeNode *) node.impl->get_tree_node(); DomTreeNode *tree_node = impl->get_tree_node(); if (new_tree_node == tree_node) return node; unsigned int cur_index = tree_node->first_attribute; unsigned int last_index = cl_null_node_index; DomTreeNode *cur_attribute = tree_node->get_first_attribute(doc_impl); while (cur_attribute) { std::string lname = cur_attribute->get_node_name(); std::string::size_type lpos = lname.find_first_of(':'); if (lpos != std::string::npos) lname = lname.substr(lpos + 1); if (cur_attribute->get_namespace_uri() == namespace_uri && lname == local_name) { new_tree_node->parent = cur_attribute->parent; new_tree_node->previous_sibling = cur_attribute->previous_sibling; new_tree_node->next_sibling = cur_attribute->next_sibling; if (cur_attribute->previous_sibling == cl_null_node_index) tree_node->first_attribute = node.impl->node_index; else cur_attribute->get_previous_sibling(doc_impl)->next_sibling = node.impl->node_index; if (cur_attribute->next_sibling != cl_null_node_index) cur_attribute->get_next_sibling(doc_impl)->previous_sibling = node.impl->node_index; cur_attribute->parent = cl_null_node_index; cur_attribute->previous_sibling = cl_null_node_index; cur_attribute->next_sibling = cl_null_node_index; return node; } last_index = cur_index; cur_index = cur_attribute->next_sibling; cur_attribute = cur_attribute->get_next_sibling(doc_impl); } if (last_index == cl_null_node_index) { tree_node->first_attribute = node.impl->node_index; new_tree_node->parent = impl->node_index; new_tree_node->previous_sibling = cl_null_node_index; new_tree_node->next_sibling = cl_null_node_index; } else { new_tree_node->parent = impl->node_index; new_tree_node->previous_sibling = last_index; new_tree_node->next_sibling = cl_null_node_index; doc_impl->nodes[last_index]->next_sibling = node.impl->node_index; } return node; }
DomNode DomNode::named_item(const DomString &name) const { DomNode node = get_first_child(); while (node.is_null() == false) { if (node.get_node_name() == name) return node; node = node.get_next_sibling(); } return DomNode(); }
DomNode DomNamedNodeMap::get_named_item(const DomString &name) const { if (!impl) return DomNode(); DomDocument_Impl *doc_impl = (DomDocument_Impl *) impl->owner_document.lock().get(); const DomTreeNode *tree_node = impl->get_tree_node(); unsigned int cur_index = tree_node->first_attribute; const DomTreeNode *cur_attribute = tree_node->get_first_attribute(doc_impl); while (cur_attribute) { if (cur_attribute->get_node_name() == name) { DomNode_Impl *dom_node = doc_impl->allocate_dom_node(); dom_node->node_index = cur_index; return DomNode(std::shared_ptr<DomNode_Impl>(dom_node, DomDocument_Impl::NodeDeleter(doc_impl))); } cur_index = cur_attribute->next_sibling; cur_attribute = cur_attribute->get_next_sibling(doc_impl); } return DomNode(); }
DomNode DomNode::named_item_ns( const DomString &namespace_uri, const DomString &local_name) const { DomNode node = get_first_child(); while (node.is_null() == false) { if (node.get_namespace_uri() == namespace_uri && node.get_local_name() == local_name) return node; node = node.get_next_sibling(); } return DomNode(); }
DomNode DomNamedNodeMap::set_named_item(const DomNode &node) { if (!impl) return DomNode(); DomDocument_Impl *doc_impl = (DomDocument_Impl *) impl->owner_document.lock().get(); DomString name = node.get_node_name(); DomTreeNode *new_tree_node = (DomTreeNode *) node.impl->get_tree_node(); DomTreeNode *tree_node = impl->get_tree_node(); if (new_tree_node == tree_node) return node; unsigned int cur_index = tree_node->first_attribute; unsigned int last_index = cl_null_node_index; DomTreeNode *cur_attribute = tree_node->get_first_attribute(doc_impl); while (cur_attribute) { if (cur_attribute->get_node_name() == name) { new_tree_node->parent = cur_attribute->parent; new_tree_node->previous_sibling = cur_attribute->previous_sibling; new_tree_node->next_sibling = cur_attribute->next_sibling; if (cur_attribute->previous_sibling == cl_null_node_index) tree_node->first_attribute = node.impl->node_index; else cur_attribute->get_previous_sibling(doc_impl)->next_sibling = node.impl->node_index; if (cur_attribute->next_sibling != cl_null_node_index) cur_attribute->get_next_sibling(doc_impl)->previous_sibling = node.impl->node_index; cur_attribute->parent = cl_null_node_index; cur_attribute->previous_sibling = cl_null_node_index; cur_attribute->next_sibling = cl_null_node_index; return node; } last_index = cur_index; cur_index = cur_attribute->next_sibling; cur_attribute = cur_attribute->get_next_sibling(doc_impl); } if (last_index == cl_null_node_index) { tree_node->first_attribute = node.impl->node_index; new_tree_node->parent = impl->node_index; new_tree_node->previous_sibling = cl_null_node_index; new_tree_node->next_sibling = cl_null_node_index; } else { new_tree_node->parent = impl->node_index; new_tree_node->previous_sibling = last_index; new_tree_node->next_sibling = cl_null_node_index; doc_impl->nodes[last_index]->next_sibling = node.impl->node_index; } return node; }
DomNode DomNode::replace_child(DomNode &new_child, DomNode &old_child) { if (impl && new_child.impl && old_child.impl) { DomTreeNode *tree_node = impl->get_tree_node(); DomTreeNode *new_tree_node = new_child.impl->get_tree_node(); DomTreeNode *old_tree_node = old_child.impl->get_tree_node(); new_tree_node->previous_sibling = old_tree_node->previous_sibling; new_tree_node->next_sibling = old_tree_node->next_sibling; new_tree_node->parent = impl->node_index; if (tree_node->first_child == old_child.impl->node_index) tree_node->first_child = new_child.impl->node_index; if (tree_node->last_child == old_child.impl->node_index) tree_node->last_child = new_child.impl->node_index; old_tree_node->previous_sibling = cl_null_node_index; old_tree_node->next_sibling = cl_null_node_index; old_tree_node->parent = cl_null_node_index; return new_child; } return DomNode(); }
DomNode DomNode::append_child(DomNode new_child) { if (impl && new_child.impl) { DomDocument_Impl *doc_impl = (DomDocument_Impl *)impl->owner_document.lock().get(); DomTreeNode *tree_node = impl->get_tree_node(); DomTreeNode *new_tree_node = new_child.impl->get_tree_node(); if (tree_node->last_child != cl_null_node_index) { DomTreeNode *last_tree_node = tree_node->get_last_child(doc_impl); last_tree_node->next_sibling = new_child.impl->node_index; new_tree_node->previous_sibling = tree_node->last_child; tree_node->last_child = new_child.impl->node_index; } else { tree_node->first_child = new_child.impl->node_index; tree_node->last_child = new_child.impl->node_index; } new_tree_node->parent = impl->node_index; return new_child; } return DomNode(); }