Skip to main content


node:addchild — Add a child node




value: mixed


When the parameter passed to this function is a string, this function creates a node and adds it as a child of the existing node, returning the new node. The parameter passed to this method is the name of the XML tag.

local doc = xml.parsexml([[<doc></doc>]]);
local node = doc:root();
local child = node:addchild("item");
child:contents("I am a child node.");

You can also pass a node object to this function, the return value of node:children, for example. When the parameter is an existing node object, it is added as a child node and the "new" node is the return value of the function.

See Also

Was this page helpful?