@XMLGetAttribute
Syntax
@XMLGetAttribute(XMLN;Options;Name);
@XMLGetAttribute(XMLN;Options;Name;Namespace);
Description
This @Function retrieves the value of a specified attribute of an XML node.
The attribute is searched by name. Optionally, a namespace can also be specified. In this case, both the attribute name and the namespace URI must match.
The search parameters are converted to UTF-8 according to the character set flags set for the XML handle. The returned attribute value is converted according to the configured output flags.
The Options parameter specifies whether the attribute value is returned as text or as a binary buffer.
VSPECHXMLNODE XMLN:
Handle of the XML node whose attributes are to be searched.
XMLN must contain a valid VSPECHXMLNODE (XMLN) handle that references an XML node.
TEXT Options:
Specifies the data type of the returned attribute value.
Option : Meaning
"A" : Returns the attribute value as TEXT.
"B" : Returns the attribute value as VSPECBINBUFFER.
With option A, the returned value must not exceed the maximum size of a text item.
TEXT Name:
Name of the attribute to search for.
TEXT Namespace (Optional)
If no namespace is specified, the search is performed using the attribute name only.
If an empty text value ("") is specified as the namespace, the function explicitly searches for an attribute without a namespace.
Return Value:
If the specified attribute is found, the @Function returns its value as TEXT or VSPECBINBUFFER, depending on Options.
If the attribute is not found, the supplied XML node handle is invalid, Options is invalid, or an error occurs during character set conversion, the @Function returns @ERROR.
Example: @XMLGetAttribute(XMLN;Options;Name);
XML := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<customer id=\"4711\" name=\"Example GmbH\" />";
hXMLD := @XMLParse(XML);
hXMLRoot := @XMLGetRoot(hXMLD);
CustomerID := @XMLGetAttribute(hXMLRoot;"A";"id");
@XMLRelease(hXMLD);
The example retrieves the value of the "id" attribute of the root element. CustomerID then contains the text "4711".
Example: @XMLGetAttribute(XMLN;Options;Name;Namespace);
XML := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<customer xmlns:c=\"https://example.com/customer\" " +
"c:id=\"4711\" />";
hXMLD := @XMLParse(XML);
hXMLRoot := @XMLGetRoot(hXMLD);
CustomerID := @XMLGetAttribute(hXMLRoot;"A";"id";"https://example.com/customer");
@XMLRelease(hXMLD);
The example retrieves the value of the "id" attribute with the namespace URI "https://example.com/customer". CustomerID then contains the text "4711".
Note : This text was machine-translated and may contain inaccuracies.
