2012-10-02 00:42:05 +04:00
|
|
|
assert(require 'pugilua')
|
|
|
|
|
|
2012-10-03 23:07:07 +04:00
|
|
|
print(pugi.version)
|
|
|
|
|
|
2012-10-02 00:42:05 +04:00
|
|
|
local doc=pugi.xml_document()
|
|
|
|
|
os.execute("cd")
|
2012-10-02 01:36:48 +04:00
|
|
|
local res=doc:load_file [[..\..\scripts\pugilua\pugilua.vcxproj]]
|
|
|
|
|
print(res.description)
|
2012-10-02 08:49:35 +04:00
|
|
|
assert(res.valid)
|
2012-10-02 01:36:48 +04:00
|
|
|
|
2012-10-03 19:18:41 +04:00
|
|
|
local node=doc:root():child('Project')
|
2012-10-02 01:36:48 +04:00
|
|
|
assert(node.valid)
|
|
|
|
|
print(node.valid)
|
2012-10-02 22:20:53 +04:00
|
|
|
print(node.name)
|
2012-10-03 19:18:41 +04:00
|
|
|
local query1=doc:root():select_nodes('Project/PropertyGroup')
|
2012-10-02 22:20:53 +04:00
|
|
|
local query2=node:select_nodes('PropertyGroup')
|
|
|
|
|
assert(query1)
|
|
|
|
|
assert(query2)
|
2012-10-03 14:58:34 +04:00
|
|
|
print(query1.type,pugi.xpath_node_set.type_sorted)
|
|
|
|
|
query1:sort(true)
|
|
|
|
|
print(query1.type,pugi.xpath_node_set.type_sorted)
|
|
|
|
|
print(query1.size,query2.size)
|
|
|
|
|
n=query1.size
|
|
|
|
|
for i=0,n-1 do
|
2012-10-03 15:28:37 +04:00
|
|
|
local node=query1:get(i):node()
|
|
|
|
|
local attribute=query1:get(i):attribute()
|
2012-10-03 21:11:09 +04:00
|
|
|
print(node.valid,node.path,attribute.valid)
|
2012-10-03 19:46:10 +04:00
|
|
|
local a=node:first_attribute()
|
|
|
|
|
while a.valid do
|
2012-10-03 20:02:49 +04:00
|
|
|
print(a.name)
|
2012-10-03 19:46:10 +04:00
|
|
|
a=a:next_attribute()
|
|
|
|
|
end
|
2012-10-03 21:14:08 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
----
|
|
|
|
|
node=doc:root():child('Project')
|
2012-10-04 23:23:08 +04:00
|
|
|
print(node.text)
|
|
|
|
|
|
|
|
|
|
----
|
|
|
|
|
doc:reset()
|
|
|
|
|
--- from the tutorial
|
|
|
|
|
-- add node with some name
|
|
|
|
|
local node = doc:root():append_child("node");
|
|
|
|
|
|
|
|
|
|
-- add description node with text child
|
|
|
|
|
local descr = node:append_child("description");
|
|
|
|
|
descr:append(pugi.node_pcdata):set_value("Simple node");
|
|
|
|
|
|
|
|
|
|
-- add param node before the description
|
|
|
|
|
local param = node:insert_child_before("param", descr);
|
|
|
|
|
|
|
|
|
|
-- add attributes to param node
|
|
|
|
|
param:append_attribute("name"):set_value("version");
|
|
|
|
|
param:append_attribute("value"):set_value(1.1);
|
|
|
|
|
param:insert_attribute_after("type", param:attribute("name")):set_value("float");
|
|
|
|
|
|
|
|
|
|
print(doc:save_file("tutorial.xml"));
|