PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • Syntax 2: Running an XPATH query on an Document XML: 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/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Executes an XPATH query:
  • Versions 21 and later
    in an variable of type xmlDocument.
    WEBDEV - Browser codePHP Not available.
    New in version 21
    in an variable of type xmlDocument.
    WEBDEV - Browser codePHP Not available.
    in an 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.
Versions 25 and later
WEBDEV - Browser code This function is now available in browser code.
New in version 25
WEBDEV - Browser code This function is now available in browser code.
WEBDEV - Browser code This function is now available in browser code.
Versions 15 and later
PHP This function is now available for PHP sites.
New in version 15
PHP This function is now available for PHP sites.
PHP This function is now available for PHP sites.
Versions 17 and later
iPhone/iPad This function is now available for iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for iPhone/iPad applications.
iPhone/iPad This function is now available for iPhone/iPad applications.
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 27 and later
Android This function is now available for Android applications.
Android Widget This function is now available in Android widget mode.
New in version 27
Android This function is now available for Android applications.
Android Widget This function is now available in Android widget mode.
Android This function is now available for Android applications.
Android Widget This function is now available in Android widget mode.
Versions 21 and later
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExécuteXPath(clDoc, "/root/text()")
IF c.IsValue THEN
Trace(c.Value)
ELSE
FOR EACH UnNoeud OF c.Node
Trace("Noeud: " + UnNoeud..Text)
END
FOR EACH attrib OF c.Attribute
Trace("Noeud: " + attrib.Nom)
END
END
New in version 21
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExécuteXPath(clDoc, "/root/text()")
IF c.IsValue THEN
Trace(c.Value)
ELSE
FOR EACH UnNoeud OF c.Node
Trace("Noeud: " + UnNoeud..Text)
END
FOR EACH attrib OF c.Attribute
Trace("Noeud: " + attrib.Nom)
END
END
clDoc is xmlDocument = XMLOpen(n, fromString)
c is xpathResult = XMLExécuteXPath(clDoc, "/root/text()")
IF c.IsValue THEN
Trace(c.Value)
ELSE
FOR EACH UnNoeud OF c.Node
Trace("Noeud: " + UnNoeud..Text)
END
FOR EACH attrib OF c.Attribute
Trace("Noeud: " + attrib.Nom)
END
END
// Chargement du fichier XML
MonDoc is string
MonDoc = fLoadText("exemple.xml")
// Texte de la requête: Recherche de la balise Index
RequêteXPATH is string = "Aide/Fonction/Index"
// Création du document
XMLDocument("Exemple", MonDoc)
IF ErrorOccurred = True THEN
Error("Le fichier n'est pas au format XML.")
RETURN
END
b is boolean
b = XMLExécuteXPath("Exemple", RequêteXPATH)
// Est-ce une requête de calcul?
IF b = True AND XMLOut("Exemple") = True THEN
 // Voilà le résultat du calcul
 Trace("XMLRésultat=" + XMLResult("Exemple"))
END
// Est-ce une requête XPath de sélection?
IF XMLFound("Exemple") = True THEN
// Parcours de la sélection résultat
WHILE XMLFound("Exemple") = True
Trace(XMLPath("Exemple"))
XMLNext("Exemple")
END
// Parcours terminé, on termine la requête
XMLCancelSearch("Exemple")
END
Syntax
Versions 21 and later
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.
get of the result:
  • The Property IsValue allows 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 Property 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 execute.
New in version 21
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.
get of the result:
  • The Property IsValue allows 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 Property 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 execute.
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.
get of the result:
  • The Property IsValue allows 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 Property 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 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 XML document> , <Text of XPath query>)
<Result>: Boolean
  • True if the query was executed,
  • False otherwise or if no element corresponds to the query.
get of 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 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 execute.
Remarks
WINDEVUniversal Windows 10 AppiPhone/iPadUser code (UMC)

Syntax 2: Running an XPATH query on an Document XML: 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 sub-element named <PRICE>count(//*[PRICE])
    Total of the invoicesum(//ITEM[PRICE])- sum(//COUPON[PRICE])
  • Query for selecting records: function XMLFound returns True.
    During a selection query, the XMLExecuteXPath function changes the current position in the current Document XML to the first result element of the selection. 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: Execute an XPATH query on an Variable of type xmlDocument:
    • 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 Document XML:
    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 Gestion des 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: wd270xml.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment