PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Syntax 2: Running an XPATH query on an XML document: Reading the result of the query
  • Limitations
  • XML functions and threads
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Runs an XPATH query:
Versions 15 and later
PHP This function is now available for the PHP sites.
New in version 15
PHP This function is now available for the PHP sites.
PHP This function is now available for the PHP sites.
PHP Only the calculation queries performed in an XML document are supported in PHP.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This function is now available in Windows Store apps mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Versions 21 and later
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExecuteXPath(clDoc, "/root/text()")
IF c..IsValue THEN
Trace(c..Value)
ELSE
FOR EACH node OF c..Node
Trace("Node: " + node..Text)
END
FOR EACH attrib OF c..Attribute
Trace("Node: " + attrib..Name)
END
END
New in version 21
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExecuteXPath(clDoc, "/root/text()")
IF c..IsValue THEN
Trace(c..Value)
ELSE
FOR EACH node OF c..Node
Trace("Node: " + node..Text)
END
FOR EACH attrib OF c..Attribute
Trace("Node: " + attrib..Name)
END
END
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExecuteXPath(clDoc, "/root/text()")
IF c..IsValue THEN
Trace(c..Value)
ELSE
FOR EACH node OF c..Node
Trace("Node: " + node..Text)
END
FOR EACH attrib OF c..Attribute
Trace("Node: " + attrib..Name)
END
END
// 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.")
RETURN
END
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"))
END
// Is it a selection XPath query?
IF XMLFound("Example") = True THEN
// Browse the result selection
WHILE XMLFound("Example") = True
Trace(XMLPath("Example"))
XMLNext("Example")
END
// Browse completed, end the query
XMLCancelSearch("Example")
END
Syntax
Versions 21 and later
PHP Syntax not available in PHP

Running 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.
Read the result:
  • ..IsValue is used to find out whether 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), ..Value is used to read the result.
<XML Document>: xmlDocument variable
Name of the xmlDocument variable containing the XML code to analyze.
<Text of XPath Query>: Character string (with quotes)
Text of the XPath query to run.
New in version 21
PHP Syntax not available in PHP

Running 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.
Read the result:
  • ..IsValue is used to find out whether 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), ..Value is used to read the result.
<XML Document>: xmlDocument variable
Name of the xmlDocument variable containing the XML code to analyze.
<Text of XPath Query>: Character string (with quotes)
Text of the XPath query to run.
PHP Syntax not available in PHP

Running 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.
Read the result:
  • ..IsValue is used to find out whether 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), ..Value is used to read the result.
<XML Document>: xmlDocument variable
Name of the xmlDocument variable containing the XML code to analyze.
<Text of XPath Query>: Character string (with quotes)
Text of the XPath query to run.

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

<Result> = XMLExecuteXPath(<Name of XML Document> , <Text of XPath Query>)
<Result>: Boolean
  • True if the query was run,
  • False otherwise or if no element corresponds to the query.
Read the result:
  • For a selection query, if the XPATH query has been run, 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 XML Document>: Character string (with quotes)
Name of XML document used. This document contains the XML code to study and it was created by XMLDocument.
<Text of XPath Query>: Character string (with quotes)
Text of the XPath query to run.
Remarks
WINDEViPhone/iPadWindows MobileUniversal Windows 10 AppUser code (UMC)

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

The query was successfully run if XMLExecuteXPath returns True. 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 sub-element named <PRICE>count(//*[PRICE])
    Total of the invoicesum(//ITEM[PRICE])- sum(//COUPON[PRICE])
  • Query for selecting records: XMLFound returns True.
    During a selection query, XMLExecuteXPath changes the current position in the current XML document in order to be positioned on the first element of the selection result. Then, XMLNext allows you to browse the selection.
    Some examples of selection queries:
    Browse all the tags whose name is "ITEM".//ITEM
    Browse all the elements with a "unit" attribute.//*[@unit]

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

Limitations

  • Several XPath browse queries cannot be nested.
  • Syntax 1: Running an XPATH query on an xmlDocument variable:
    • The list of nodes is not sorted.
    • The standard used for the XPath query is XPath 1.0.
  • Syntax 2: Running 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 is using threads, the XML document is shared among all these threads. See Managing the threads for more details.
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.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230xml.dll
Windows Mobile wp230xml.dll
Linux wd230xml.so
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment