diff --git a/Lua/lib/pugilua.dll b/Lua/lib/pugilua.dll index b6b996a..187336a 100644 Binary files a/Lua/lib/pugilua.dll and b/Lua/lib/pugilua.dll differ diff --git a/Lua/lib/pugilua.lib b/Lua/lib/pugilua.lib index adc67aa..42378b5 100644 Binary files a/Lua/lib/pugilua.lib and b/Lua/lib/pugilua.lib differ diff --git a/Lua/lib/test.lua b/Lua/lib/test.lua index 8843737..1995c24 100644 --- a/Lua/lib/test.lua +++ b/Lua/lib/test.lua @@ -22,7 +22,7 @@ n=query1.size for i=0,n-1 do local node=query1:get(i):node() local attribute=query1:get(i):attribute() - print(node.valid,attribute.valid) + print(node.valid,node.path,attribute.valid) local a=node:first_attribute() while a.valid do print(a.name) diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index 6ae0ae7..ffa7156 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -89,8 +89,6 @@ namespace pugi { std::string name() const; std::string value() const; - RefCountedPtr select_nodes(char const* query); - bool empty() const; int type() const; //todo: define constants @@ -152,7 +150,15 @@ namespace pugi { 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() + std::string path() const; + + RefCountedPtr first_element_by_path(const char* path) const; + + RefCountedPtr select_single_node(const char* query) const; + + RefCountedPtr select_nodes(char const* query) const; + + //todo: text(), xml_tree_walker somehow public: // non-lua interface pugi::xml_node const& get() const; @@ -257,7 +263,7 @@ namespace pugi { return node.value(); } - RefCountedPtr lxml_node::select_nodes(char const* query) { + RefCountedPtr lxml_node::select_nodes(char const* query) const { try { return RefCountedPtr(new lxpath_node_set(node.select_nodes(query))); } catch (pugi::xpath_exception const& e) { @@ -434,6 +440,23 @@ namespace pugi { return RefCountedPtr(new lxml_node(node.find_child_by_attribute(attr_name,attr_name,attr_value))); } + std::string lxml_node::path() const { + return node.path(); + } + + RefCountedPtr lxml_node::first_element_by_path(const char* path) const { + return RefCountedPtr(new lxml_node(node.first_element_by_path(path))); + } + + RefCountedPtr lxml_node::select_single_node(char const* query) const { + try { + return RefCountedPtr(new lxpath_node(node.select_single_node(query))); + } catch (pugi::xpath_exception const& e) { + std::cerr<<"Error: "<(new lxpath_node()); + } + } + /////////////////// RefCountedPtr lxml_document::load_file(char const* path) { return RefCountedPtr(new lxml_parse_result(doc.load_file(path))); @@ -522,8 +545,8 @@ void register_pugilua (lua_State* L) { .addProperty("name",&lxml_node::name) .addProperty("value",&lxml_node::value) .addProperty("type",&lxml_node::type) + .addProperty("path",&lxml_node::path) .addFunction("child",&lxml_node::child) - .addFunction("select_nodes",&lxml_node::select_nodes) .addFunction("first_attribute",&lxml_node::first_attribute) .addFunction("last_attribute",&lxml_node::last_attribute) .addFunction("first_child",&lxml_node::first_child) @@ -564,6 +587,9 @@ void register_pugilua (lua_State* L) { .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) + .addFunction("first_element_by_path",&lxml_node::first_element_by_path) + .addFunction("select_single_node",&lxml_node::select_single_node) + .addFunction("select_nodes",&lxml_node::select_nodes) .endClass() .beginClass("xml_document")