From 07944e48c60de15a34873736227b447b3ba80b4f Mon Sep 17 00:00:00 2001 From: d-led Date: Wed, 3 Oct 2012 17:18:41 +0200 Subject: [PATCH] lxml_document not implementing lxml_node returns root as xml_node instead --- Lua/lib/test.lua | 4 ++-- contrib/pugilua/pugilua_lib.cpp | 20 ++++---------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Lua/lib/test.lua b/Lua/lib/test.lua index bfb6498..045e71e 100644 --- a/Lua/lib/test.lua +++ b/Lua/lib/test.lua @@ -6,11 +6,11 @@ local res=doc:load_file [[..\..\scripts\pugilua\pugilua.vcxproj]] print(res.description) assert(res.valid) -local node=doc:child('Project') +local node=doc:root():child('Project') assert(node.valid) print(node.valid) print(node.name) -local query1=doc:select_nodes('Project/PropertyGroup') +local query1=doc:root():select_nodes('Project/PropertyGroup') local query2=node:select_nodes('PropertyGroup') assert(query1) assert(query2) diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index 73264bf..740b994 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -98,9 +98,7 @@ namespace pugi { public: RefCountedPtr load_file(char const* path); - RefCountedPtr child(char const* name); - - RefCountedPtr select_nodes(char const* query); + RefCountedPtr lxml_document::root() const; bool valid() const; @@ -201,17 +199,8 @@ namespace pugi { return RefCountedPtr(new lxml_parse_result(doc.load_file(path))); } - RefCountedPtr lxml_document::child(char const* name) { - return RefCountedPtr(new lxml_node(doc.child(name))); - } - - RefCountedPtr lxml_document::select_nodes(char const* query) { - try { - return RefCountedPtr(new lxpath_node_set(doc.select_nodes(query))); - } catch (pugi::xpath_exception const& e) { - std::cerr<<"Error: "<(new lxpath_node_set()); - } + RefCountedPtr lxml_document::root() const { + return RefCountedPtr(new lxml_node(pugi::xml_node(doc))); } bool lxml_document::valid() const { @@ -299,8 +288,7 @@ void register_pugilua (lua_State* L) { .addConstructor() .addProperty("valid",&lxml_document::valid) .addFunction("load_file",&lxml_document::load_file) - .addFunction("child",&lxml_document::child) - .addFunction("select_nodes",&lxml_document::select_nodes) + .addFunction("root",&lxml_document::root) .endClass() .beginClass("xpath_node")