@XMLSelectNodes
Syntax
@XMLSelectNodes(XMLN;XPath);
@XMLSelectNodes(XMLN;XPath;Prefix;Namespace);
Description
This @Function evaluates an XPath expression relative to an XML node and returns all matching XML nodes as a VSPECHXMLNODELIST (XMLNL) handle.
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 list 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 matching nodes are found, the @Function returns a VSPECHXMLNODELIST (XMLNL) handle containing all matching nodes.
The matching nodes are sorted into document order before being returned.
The number of contained nodes can be retrieved using @XMLNodeListGetElements. Individual nodes can be retrieved using @XMLNodeListGetNode.
The returned node list handle should be released using @XMLNodeListRelease after processing has been completed.
If no matching object is found, the XPath evaluation does not return a node set, the supplied XML node handle is invalid, or another error occurs, the @Function returns @ERROR.
Example: @XMLSelectNodes(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);
hXMLNL := @XMLSelectNodes(hXMLRoot;"customer");
Elements := @XMLNodeListGetElements(hXMLNL);
@XMLNodeListRelease(hXMLNL);
@XMLRelease(hXMLD);
The example retrieves all direct child <customer> elements. Elements then contains the value 2.
Example: @XMLSelectNodes(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);
hXMLNL := @XMLSelectNodes(
hXMLRoot;
"c:customer";
"c";
"https://example.com/customer"
);
Elements := @XMLNodeListGetElements(hXMLNL);
@XMLNodeListRelease(hXMLNL);
@XMLRelease(hXMLD);
The example registers the prefix "c" for the namespace URI "https://example.com/customer" and then retrieves all matching "<c:customer>" elements.
Note : This text was machine-translated and may contain inaccuracies.
