Cicode Programming Reference > Cicode Function Categories > XML Functions > XMLNodeAddChild

XMLNodeAddChild

Creates an element node with the specified Name and Namespace and appends the node to the end of the list of child nodes of specified parent node in the XML document.

Syntax

INT XMLNodeAddChild(INT hDoc, INT hNode, STRING sName[, STRING sNamespace = "" ])

hDoc

Handle of the XML document the parent node belongs to. Returned by XMLCreate or XMLOpen.

hNode

Handle of the parent node.e.g. <shapes>, <polygons>, <polygon>. Returned by XMLGetRoot, XMLGetChild, XMLGetParent or XMLNodeFind.

sName

The qualified name of the new element node.

sNamespace

Optional parameter. The namespace URI of the new node.E.g.<shapes xmlns="http://schneider-electric.com/shapes/v1">.

Return Value

Handle of the newly created node, or -1 on error.

Related Functions

XMLClose, XMLCreate, XMLGetAttribute, XMLGetAttributeCount, XMLGetAttributeName, XMLGetAttributeValue, XMLGetChild, XMLGetChildCount, XMLGetParent, XMLGetRoot, XMLNodeFind, XMLNodeGetName, XMLNodeGetValue, XMLNodeRemove, XMLNodeSetValue, XMLOpen, XMLSave, XMLSetAttribute

Example

The example adds a new element node to the root of XML document and then adds two new element nodes to the first created node.

 

		INT hDoc, hRoot, hNode;
		hDoc = XMLCreate("shapes",  "http://schneider-electric.com/shapes/v1");
		IF hDoc <> -1 THEN
			hRoot = XMLGetRoot(hDoc);
			IF hRoot <> -1 THEN
				hNode = XMLNodeAddChild(hDoc, hRoot, "polygons");
				IF hNode <> -1 THEN
					XMLNodeAddChild(hDoc, hNode, "polygon");
					XMLNodeAddChild(hDoc, hNode, "polygon");
				END
			END
		END

			

The xml document created by the code above:

		
			 
		<?xml version="1.0" encoding="utf-8" ?>
		<shapes xmlns="http://schneider-electric.com/shapes/v1">
		<polygons>
			<polygon/>
			<polygon/>
		</polygons>
		</shapes> 
			

See Also

XML Functions

Published June 2018