From d8c65911ceb471ea7209c28c7886222f47a75ed1 Mon Sep 17 00:00:00 2001 From: d-led Date: Wed, 3 Oct 2012 18:57:55 +0200 Subject: [PATCH] child removal and search by attribute --- contrib/pugilua/pugilua_lib.cpp | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index c3b8bd9..6ae0ae7 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -143,6 +143,15 @@ namespace pugi { RefCountedPtr insert_copy_after(RefCountedPtr proto, RefCountedPtr _node); RefCountedPtr insert_copy_before(RefCountedPtr proto, RefCountedPtr _node); + bool remove_attribute(RefCountedPtr a); + bool remove_attribute_by_name(const char* name); + + bool remove_child(RefCountedPtr n); + bool remove_child_by_name(const char* name); + + RefCountedPtr find_child_by_name_and_attribute(const char* name, const char* attr_name, const char* attr_value) const; + RefCountedPtr find_child_by_attribute(const char* attr_name, const char* attr_value) const; + //todo: text() public: // non-lua interface @@ -401,6 +410,30 @@ namespace pugi { return RefCountedPtr(new lxml_node(node.insert_copy_before(proto->get(),_node->get()))); } + bool lxml_node::remove_attribute(RefCountedPtr a) { + return node.remove_attribute(a->get()); + } + + bool lxml_node::remove_attribute_by_name(const char* name) { + return node.remove_attribute(name); + } + + bool lxml_node::remove_child(RefCountedPtr n) { + return node.remove_child(n->get()); + } + + bool lxml_node::remove_child_by_name(const char* name) { + return node.remove_child(name); + } + + RefCountedPtr lxml_node::find_child_by_name_and_attribute(const char* name, const char* attr_name, const char* attr_value) const { + return RefCountedPtr(new lxml_node(node.find_child_by_attribute(name,attr_name,attr_value))); + } + + RefCountedPtr lxml_node::find_child_by_attribute(const char* attr_name, const char* attr_value) const { + return RefCountedPtr(new lxml_node(node.find_child_by_attribute(attr_name,attr_name,attr_value))); + } + /////////////////// RefCountedPtr lxml_document::load_file(char const* path) { return RefCountedPtr(new lxml_parse_result(doc.load_file(path))); @@ -525,6 +558,12 @@ void register_pugilua (lua_State* L) { .addFunction("prepend_copy",&lxml_node::prepend_copy) .addFunction("insert_copy_after",&lxml_node::insert_copy_after) .addFunction("insert_copy_before",&lxml_node::insert_copy_before) + .addFunction("remove_attribute",&lxml_node::remove_attribute) + .addFunction("remove_attribute_by_name",&lxml_node::remove_attribute_by_name) + .addFunction("remove_child",&lxml_node::remove_child) + .addFunction("remove_child_by_name",&lxml_node::remove_child_by_name) + .addFunction("find_child_by_name_and_attribute",&lxml_node::find_child_by_name_and_attribute) + .addFunction("find_child_by_attribute",&lxml_node::find_child_by_attribute) .endClass() .beginClass("xml_document")