attributes of xml_nodes traversable

This commit is contained in:
d-led 2012-10-03 17:46:10 +02:00
parent 07944e48c6
commit 3d2d6d4f67
2 changed files with 36 additions and 5 deletions

View File

@ -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

View File

@ -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<lxml_node> child(char const* name);
RefCountedPtr<lxml_node> child(char const* name) const;
std::string name() const;
std::string value() const;
RefCountedPtr<lxpath_node_set> select_nodes(char const* query);
bool empty () const;
bool empty() const;
int type() const; //todo: define constants
RefCountedPtr<lxml_attribute> first_attribute() const;
RefCountedPtr<lxml_attribute> last_attribute() const;
private:
pugi::xml_node node;
@ -173,7 +179,7 @@ namespace pugi {
return (bool)node;
}
RefCountedPtr<lxml_node> lxml_node::child(char const* name) {
RefCountedPtr<lxml_node> lxml_node::child(char const* name) const {
return RefCountedPtr<lxml_node>(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<lxpath_node_set> lxml_node::select_nodes(char const* query) {
try {
return RefCountedPtr<lxpath_node_set>(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_attribute> lxml_node::first_attribute() const {
return RefCountedPtr<lxml_attribute>(new lxml_attribute(node.first_attribute()));
}
RefCountedPtr<lxml_attribute> lxml_node::last_attribute() const {
return RefCountedPtr<lxml_attribute>(new lxml_attribute(node.last_attribute()));
}
///////////////////
RefCountedPtr<lxml_parse_result> lxml_document::load_file(char const* path) {
return RefCountedPtr<lxml_parse_result>(new lxml_parse_result(doc.load_file(path)));
@ -280,8 +302,12 @@ void register_pugilua (lua_State* L) {
.addConstructor<void (*)()>()
.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<lxml_document>("xml_document")