Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • Declaring an xmlDocument variable
  • Properties specific to the description of the xmlDocument variables
  • Using the indirection on the paths in an XML document
  • Functions that use the xmlDocument variables
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
The xmlDocument type is used to handle an XML file. The characteristics of this file can be defined and modified using different WLanguage properties.
Remark: For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable.
// Exemple utilisant le fichier XML suivant: piece_theatre.xml
// <?xml version="1.0"?>
// <PLAY>
// <TITLE>Titre de la piece</TITLE>
// <PERSONA>Un personnage</PERSONA>
// <ACT>
// <SCENE>
// <LINE></LINE>
// </SCENE>
// </ACT>
// </PLAY>
// Déclaration d'une variable xmlDocument utilisant un modèle de document
RomeoEtJuliette is xmlDocument, description = "piece_theatre.xml"
// Chargement d'un document XML depuis un fichier
RomeoEtJuliette = XMLOpen("romeo_et_juliette.xml", fromFile)
// Affichage du numéro de version du XML
// Affichage du titre de la pièce en accédant directement aux noeuds

Declaring an xmlDocument variable

The xmlDocument variables can be declared by indicating a sample document (XML file) or a template document (XSD file). The structure of this document will be read by WINDEV, WEBDEV and WINDEV Mobile. Therefore, the automatic completion will be available for the names of nodes in the code editor.
To declare an xmlDocument variable with a sample document:
  1. Add the XML document into the project via one of the following methods:
    • on the "Project" tab, in the "Project" group, expand " List of elements" and click "List of project elements". The list of project elements is displayed. Click the "Add" button and select the XML document.
    • drag the file and drop it in the "External descriptions" folder of the "Project explorer" pane.
    • in the "Project explorer" pane, select the "External descriptions" folder, then:
      • "Import an XML or JSON into this project" in the context menu.
      • "Import an XSD into this project" in the context menu.
  2. The XML document appears in the "External descriptions" folder of the project explorer. You have the ability to see its structure.
  3. Declare the variable as follows:
    <Nom de la variable> est un xmlDocument , description =  <Nom du document>

    <Document name> can correspond to the name of sample document (with or without extension) or to the name of template document (with or without extension).
    • This declaration can be obtained automatically by "dropping" the name of the Document XML directly from the "Project Explorer" pane..
    • When using a sample document, you also have the ability to use the following syntax:
      <Nom de la variable> est un xmlDocument
      <Nom de la variable> = XMLOuvre(<Nom du document>)
  4. You now have the ability to access the variable nodes by their names. These names are automatically proposed by the mechanism for automatic completion of the code editor.
Remark: XMLSave is used to save the XML document. If an XSD file was used, it will be automatically taken into account.

Properties specific to the description of the xmlDocument variables

The following properties can be used to handle an xmlDocument variable:
NameType usedEffect
EncodingCharacter stringEncoding used for the character strings of the XML document. The UTF-8 encoding is used if this property is not specified or if it is set to "" (empty string). This is the case for example during a conversion into string with XMLBuildString.
RootNodeArray of xmlNodeArray of root nodes of the XML document.
A valid XML document must have a single root node. However, several nodes can be found at the root when building the document.
VersionCharacter stringVersion of the XML format. In most cases, this property is set to "1.0".

Remark: These properties can be used with one of the following syntaxes:
  • <Variable name>..<Property name>
  • <Variable name>.<Property name>

Using the indirection on the paths in an XML document

The indirection operators can be used to build the path of an element in an XML document.
sDocXML is string = [
<?xml version="1.0" encoding="UTF-8"?>
xmlExemple is xmlDocument = XMLOpen(sDocXML, fromString)
sParam is string = "WinDev_Param"
// Lecture directe d'une information ...
// Lecture avec une partie du chemin XML contenu dans une variable
// (idem si rubrique d'un fichier, paramètre d'une fenêtre, méthode, ...)
sParamètre is string = "InfoVersion"
Trace({"xmlExemple.Document." + sParamètre + ".Version"})

Functions that use the xmlDocument variables

XMLBuildStringRetrieves and formats the content of an XML document (created by XMLDocument and modified by the XML functions).
XMLOpenLoads an XML document from a file, a URL or a string into an xmlDocument variable.
XMLSaveSaves an XML document in a file.
XMLValidDocumentValidates an XML document from an XSD schema.
Note: The browse of an XMLDocument variable must be performed by using the FOR EACH syntax. XMLRead must not be used.
Minimum version required
  • Version 15
This page is also available for…
Click [Add] to post a comment