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

XMLSetAttribute

Use this function to set the value of specified attribute of the node in the XML document. If the attribute does not exist, it will be created.

Syntax

INT XMLSetAttribute(INT hDoc, INT hNode, STRING sName, STRING sValue)

hDoc

Handle of the XML document. Returned by XMLCreate or XMLOpen.

hNode

Handle of the node. Returned by XMLGetRoot, XMLGetChild, XMLGetParent or XMLNodeFind.

sName

The name of the attribute.

sValue

The value of the attribute

Return Value

0 (zero) if successful, otherwise an error code is returned.

Related Functions

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

Example

Following example creates an XML document from local file "H:\Data\books.xml", then selects the first node that matches XPath expression "/bookstore/book/" and sets the value of the node’s attribute "Language" to "English".

		INT hDoc, hNode;
		hDoc = XMLOpen("H:\Data\books.xml");
		IF hDoc less -1 THEN
			hNode = XMLNodeFind(hDoc,"/bookstore/book/");
			IF hNode less -1 THEN
				XMLSetAttribute(hDoc,  hNode, "Language", "English");	
			END
		END  

			

See Also

XML Functions

Published June 2018