printing to string -> node.text

This commit is contained in:
d-led 2012-10-03 19:14:08 +02:00
parent 3e8bdc9a22
commit 347ac65743
4 changed files with 15 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -28,4 +28,8 @@ for i=0,n-1 do
print(a.name) print(a.name)
a=a:next_attribute() a=a:next_attribute()
end end
end end
----
node=doc:root():child('Project')
print(node.text)

View File

@ -5,6 +5,7 @@
#include <RefCountedPtr.h> #include <RefCountedPtr.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream>
namespace pugi { namespace pugi {
namespace lua { namespace lua {
@ -158,6 +159,8 @@ namespace pugi {
RefCountedPtr<lxpath_node_set> select_nodes(char const* query) const; RefCountedPtr<lxpath_node_set> select_nodes(char const* query) const;
std::string text() const;
//todo: text(), xml_tree_walker somehow //todo: text(), xml_tree_walker somehow
public: // non-lua interface public: // non-lua interface
@ -457,6 +460,12 @@ namespace pugi {
} }
} }
std::string lxml_node::text() const {
std::stringstream ss;
node.print(ss);
return ss.str();
}
/////////////////// ///////////////////
RefCountedPtr<lxml_parse_result> lxml_document::load_file(char const* path) { RefCountedPtr<lxml_parse_result> lxml_document::load_file(char const* path) {
return RefCountedPtr<lxml_parse_result>(new lxml_parse_result(doc.load_file(path))); return RefCountedPtr<lxml_parse_result>(new lxml_parse_result(doc.load_file(path)));
@ -546,6 +555,7 @@ void register_pugilua (lua_State* L) {
.addProperty("value",&lxml_node::value) .addProperty("value",&lxml_node::value)
.addProperty("type",&lxml_node::type) .addProperty("type",&lxml_node::type)
.addProperty("path",&lxml_node::path) .addProperty("path",&lxml_node::path)
.addProperty("text",&lxml_node::text)
.addFunction("child",&lxml_node::child) .addFunction("child",&lxml_node::child)
.addFunction("first_attribute",&lxml_node::first_attribute) .addFunction("first_attribute",&lxml_node::first_attribute)
.addFunction("last_attribute",&lxml_node::last_attribute) .addFunction("last_attribute",&lxml_node::last_attribute)