diff --git a/Lua/lib/test.lua b/Lua/lib/test.lua index 045e71e..92a87de 100644 --- a/Lua/lib/test.lua +++ b/Lua/lib/test.lua @@ -23,4 +23,9 @@ for i=0,n-1 do local node=query1:get(i):node() local attribute=query1:get(i):attribute() print(node.valid,attribute.valid) + local a=node:first_attribute() + while a.valid do + print('\t',a.name,a.value) + a=a:next_attribute() + end end \ No newline at end of file diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index 740b994..0ecba71 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -56,11 +56,11 @@ namespace pugi { bool valid() const; - int status() const { + int status() const { //todo: define constants return res.status; } - int encoding() const { + int encoding() const { //todo: define constants return res.encoding; } @@ -81,13 +81,19 @@ namespace pugi { public: bool valid() const; - RefCountedPtr child(char const* name); + RefCountedPtr child(char const* name) const; std::string name() const; + std::string value() const; RefCountedPtr select_nodes(char const* query); - bool empty () const; + bool empty() const; + + int type() const; //todo: define constants + + RefCountedPtr first_attribute() const; + RefCountedPtr last_attribute() const; private: pugi::xml_node node; @@ -173,7 +179,7 @@ namespace pugi { return (bool)node; } - RefCountedPtr lxml_node::child(char const* name) { + RefCountedPtr lxml_node::child(char const* name) const { return RefCountedPtr(new lxml_node(node.child(name))); } @@ -181,6 +187,10 @@ namespace pugi { return node.name(); } + std::string lxml_node::value() const { + return node.value(); + } + RefCountedPtr lxml_node::select_nodes(char const* query) { try { return RefCountedPtr(new lxpath_node_set(node.select_nodes(query))); @@ -194,6 +204,18 @@ namespace pugi { return node.empty(); } + int lxml_node::type() const { + return node.type(); + } + + RefCountedPtr lxml_node::first_attribute() const { + return RefCountedPtr(new lxml_attribute(node.first_attribute())); + } + + RefCountedPtr lxml_node::last_attribute() const { + return RefCountedPtr(new lxml_attribute(node.last_attribute())); + } + /////////////////// RefCountedPtr lxml_document::load_file(char const* path) { return RefCountedPtr(new lxml_parse_result(doc.load_file(path))); @@ -280,8 +302,12 @@ void register_pugilua (lua_State* L) { .addConstructor() .addProperty("valid",&lxml_node::valid) .addProperty("name",&lxml_node::name) + .addProperty("value",&lxml_node::value) + .addProperty("type",&lxml_node::type) .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) .endClass() .beginClass("xml_document")