Skip to main content

Name

node:name — Return the name of a node

Synopsis

require('xml');

node:name();

Description

This function returns the element name of a node and returns the string "text" for text nodes.

doc = xml.parsexml([[<doc></doc>]]);
local node = doc:root();
local child = node:addchild("item");
child:attr("name", "Junior");
child:contents("I am a child node.");
node:children();
for kid in child:children() do
  print(kid:name());
end

The code shown in “node:name example” results in the following output:

item
text

If you remove the line, child:contents("I am a child node.");, from “node:name example”, item is all that will be output.

See Also

Was this page helpful?