Help / WLanguage / WLanguage functions / Standard functions / XML file functions
  • Syntax 2: Executing an XPATH query on an XML document: Reading the result of the query
  • Limitations
  • XML functions and threads
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
Executes an XPATH query:
  • in a variable of type xmlDocument.
    WEBDEV - Browser codePHP Not available.
  • in an XML document.
    AndroidAndroid Widget Not available.
PHP Only the calculation queries performed in an XML document are supported in PHP.
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExecuteXPath(clDoc, "/root/text()")
IF c.IsValue THEN
FOR EACH ANode OF c.Node
Trace("Node: " + ANode..Text)
FOR EACH attrib OF c.Attribute
Trace("Node: " + attrib.Name)
// Load the XML file
MyDoc is string
MyDoc = fLoadText("example.xml")
// Text of query: Find the Index tag
XPATHQuery is string = "Help/Function/Index"
// Create the document
XMLDocument("Example", MyDoc)
IF ErrorOccurred = True THEN
Error("The file is not in XML format.")
b is boolean
b = XMLExecuteXPath("Example", XPATHQuery)
// Is it a calculation query?
IF b = True AND XMLOut("Example") = True THEN
 // The calculation result is as follows
 Trace("XMLResult=" + XMLResult("Example"))
// Is it a selection XPath query?
IF XMLFound("Example") = True THEN
// Browse the result selection
WHILE XMLFound("Example") = True
// Browse completed, end the query
WEBDEV - Browser codePHP Syntax not available in PHP and browser code

Executing an XPATH query on an xmlDocument variable Hide the details

<Result> = XMLExecuteXPath(<XML document> , <Text of XPath query>)
<Result>: xpathResult variable
xpathResult variable containing the result of the XPATH query.
Reading the result:
  • The IsValue property allows you to know if the result is a value.
  • For a selection query (the result is not a value), the xpathResult variable must be browsed.
  • For a calculation query (the result is a value), the Value property reads the result.
<XML document>: xmlDocument variable
Name of the xmlDocument variable containing the XML code to analyze.
<Text of XPath query>: Character string
Text of the XPath query to execute.
AndroidAndroid Widget Syntax not available in Android and Android Widget

Executing an XPATH query on an XML document (syntax kept for backward compatibility) Hide the details

<Result> = XMLExecuteXPath(<Name of the XML document> , <Text of XPath query>)
<Result>: Boolean
  • True if the query was executed,
  • False otherwise or if no element corresponds to the query.
Reading the result:
  • For a selection query, if the XPATH query has been executed, the XML search functions are used to browse the result of the XPATH query.
  • For a calculation query, XMLResult is used to read the result.
<Name of the XML document>: Character string
Name of the XML document used. This document contains the XML code to study and it was created by XMLDocument.
<Text of XPath query>: Character string
Text of the XPath query to execute.
WINDEVUniversal Windows 10 AppiPhone/iPadUser code (UMC)

Syntax 2: Executing an XPATH query on an XML document: Reading the result of the query

If XMLExecuteXPath returns True, the query has been successfully executed.. The result of the query can be read as follows:
  • Calculation query: XMLFound returns False.
    The result can be read by XMLResult.
    Some examples of calculation queries:
    Counting the number of tags whose name is "ITEM", which means the number of different items found in the order.count(//ITEM)
    Number of tags containing a subelement named <PRICE>count(//*[PRICE])
    Total of the invoicesum(//ITEM[PRICE])- sum(//COUPON[PRICE])
  • Query for selecting records: XMLFound returns True.
    In a selection query, XMLExecuteXPath changes the current position in the XML document to set the position on the first element of the selection result. Then, XMLNext allows you to browse the selection.
    Some examples of selection queries:
    Browse all the elements with a "unit" attribute.//*[@unit]
    Browse all the tags whose name is "ITEM".//ITEM

    To cancel the query and to browse the entire document again, use XMLCancelSearch.


  • Several XPath browse queries cannot be nested.
  • Syntax 1: Executing an XPATH query on a variable of type xmlDocument:
    • The list of nodes is not sorted.
    • The standard used for the XPath query is XPath 1.0.
  • Syntax 2: Executing an XPATH query on an XML document:
    XMLSavePosition and XMLRestorePosition cannot be used to save/restore a position when browsing the result of a select XPath query.

XML functions and threads

If your application uses threads, the XML document is shared between all these threads. For more details on threads, see Managing threads.

If the current position in an XML document is modified in a thread, the current position in this XML document is modified for all the threads.
Business / UI classification: Business Logic
Component: wd300xml.dll
Minimum version required
  • Version 9
This page is also available for…
Click [Add] to post a comment

Last update: 07/03/2023

Send a report | Local help