@XMLSetAttribute
Syntax
@XMLSetAttribute(XMLN;Name;Value);
@XMLSetAttribute(XMLN;Name;Value;Namespace);
Description
This @Function sets the value of an attribute of an XML node.
If the specified attribute already exists, its value is updated. Otherwise, a new attribute is created.
Optionally, a namespace URI can be specified. In this case, the namespace must already be defined in the XML document and must have a namespace prefix.
The attribute name, attribute value, and optional namespace URI are converted to UTF-8 according to the character set flags set for the XML handle.
VSPECHXMLNODE XMLN:
Handle of the XML node whose attribute is to be set.
XMLN must contain a valid VSPECHXMLNODE (XMLN) handle that references an XML node.
TEXT Name:
Name of the attribute to be set.
The name must not be empty and must be a valid XML NCName.
TEXT Value:
Value of the attribute.
TEXT Namespace (Optional)
Namespace URI to be assigned to the attribute.
The specified namespace URI must already be defined in the XML document and must be accessible from the XML node.
Since XML attributes do not inherit the default namespace, the specified namespace must have a prefix.
If an empty text value ("") is specified as the namespace, the attribute is set without a namespace.
Return Value:
On successful execution, the @Function returns TRUE.
If the XML node handle is invalid, the attribute name is empty or invalid, the specified namespace is not defined or has no prefix,
or the attribute cannot be set, the @Function returns @ERROR.
Example: @XMLSetAttribute(XMLN;Name;Value);
Flags := 7;
hXMLD := @XMLCreate(Flags);
hXMLRoot := @XMLCreateRoot(hXMLD;"customer");
@XMLSetAttribute(hXMLRoot;"id";"4711");
XML := @XMLSerialize(hXMLD);
@XMLRelease(hXMLD);
The example sets the attribute id="4711" on the root element.
Example: @XMLSetAttribute(XMLN;Name;Value;Namespace);
Flags := 7;
hXMLD := @XMLCreate(Flags);
hXMLRoot := @XMLCreateRoot(
hXMLD;
"customer";
"c";
"https://example.com/customer"
);
@XMLSetAttribute(
hXMLRoot;
"id";
"4711";
"https://example.com/customer"
);
XML := @XMLSerialize(hXMLD);
@XMLRelease(hXMLD);
The example sets the "id" attribute in the already defined namespace "https://example.com/customer". The resulting attribute is equivalent to c:id="4711".
Note : This text was machine-translated and may contain inaccuracies.
