Function EN Version 10.01

@XMLSelectSingleNode

XML

Syntax

@XMLSelectSingleNode(XMLN;XPath);
@XMLSelectSingleNode(XMLN;XPath;Prefix;Namespace);

Description

This @Function evaluates an XPath expression relative to an XML node and returns the first matching XML element.
Optionally, namespace prefixes and their corresponding namespace URIs can also be specified. These are registered in the XPath context before the expression is evaluated.
Exactly two call variants are supported: either with two parameters or with four parameters. A variant with three parameters is not supported.
The XPath, prefix, and namespace parameters are converted to UTF-8 according to the character set flags set for the XML handle.
The flags inherited from the supplied XML node handle are also applied to the returned XML node handle.

VSPECHXMLNODE XMLN:
Handle of the XML node to be used as the starting point for the XPath evaluation.
XMLN must contain a valid VSPECHXMLNODE (XMLN) handle that references an XML node.

TEXT XPath:
XPath expression to be evaluated relative to the supplied XML node.
The result must contain a node set. The first XML element from that node set is returned.

TEXT/TEXTLIST Prefix (Optional):
Namespace prefix or list of namespace prefixes used within the XPath expression.

TEXT/TEXTLIST Namespace (Optional):
Namespace URI or list of namespace URIs corresponding to the specified prefixes.
Prefix and Namespace must contain the same number of elements.
The specified prefixes and namespace URIs are registered pairwise in the XPath context.

Return Value:
If at least one matching XML element is found, the @Function returns a VSPECHXMLNODE (XMLN) handle referencing the first matching element.
If multiple nodes are found, the node set is sorted first and the first entry is then used.
If no matching object is found, the XPath evaluation does not return a node set, the first matching object is not an XML element, or another error occurs, the @Function returns @ERROR.

Example: @XMLSelectSingleNode(XMLN;XPath);

XML := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<customers>" +
" <customer id=\"1\"><name>Example GmbH</name></customer>" +
" <customer id=\"2\"><name>Sample GmbH</name></customer>" +
"</customers>";
hXMLD := @XMLParse(XML);
hXMLRoot := @XMLGetRoot(hXMLD);
hCustomer := @XMLSelectSingleNode(hXMLRoot;"customer[@id=’2′]");
@XMLRelease(hXMLD);

The example searches relative to the root element for the first "<customer>" element with the attribute id="2".

Example: @XMLSelectSingleNode(XMLN;XPath;Prefix;Namespace);

XML := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<customers xmlns:c=\"https://example.com/customer\">" +
" <c:customer id=\"1\"><c:name>Example GmbH</c:name></c:customer>" +
" <c:customer id=\"2\"><c:name>Sample GmbH</c:name></c:customer>" +
"</customers>";
hXMLD := @XMLParse(XML);
hXMLRoot := @XMLGetRoot(hXMLD);
hCustomer := @XMLSelectSingleNode(
hXMLRoot;
"c:customer[@id=’2′]";
"c";
"https://example.com/customer"
);

@XMLRelease(hXMLD);

The example registers the prefix "c" for the namespace URI "https://example.com/customer" and then searches for the first matching "<c:customer>" element.

Note : This text was machine-translated and may contain inaccuracies.