- Two methods
- Using an xmlDocument variable
- Using a string variable
WINDEV, WINDEV Mobile and WEBDEV include several functions for handling XML code. The XML code used must comply with the XML standard. See a documentation specific to XML for more details.
The XML code is used for example:
XML is a language containing tags and attributes (called "elements" in this help).
The structure of an XML code corresponds to a tree structure: the information is organized hierarchically.
The following terms are used to describe the different parts of an XML code:
XML code (or content) corresponds to:
- the content of an XML file.
- a response from an XML Webservice.
The XML functions allow you to:
- read, find and analyze the content of an XML file.
- modify the content of an XML file.
- format the content of an XML file.
- run an XPATH query in the content of an XML file.
- analyze the responses received from the XML Webservices.
- import data (HImportXML).
Using an xmlDocument variable
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:
- 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.
- The XML document appears in the "External descriptions" folder of the project explorer. You have the ability to see its structure.
- 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>)
- 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.
is used to save the XML document. If an XSD file was used, it will be automatically taken into account.
Using a string variable
To handle an XML code:
- Store the XML code in a string variable (fLoadText). This code can come from an XML file or from an XML Web service.
- Create an XML document (XMLDocument). This document is stored in memory and it contains the entire XML code to use.
- Handle your XML document with the WLanguage functions. You can:
- Browse XML code (XMLLast, XMLOut, XMLChild, XMLParent, XMLPrevious, XMLFirst, XMLRoot, XMLNext, XMLFound).
- Perform searches (XMLFind, XMLCancelSearch, XMLExtractString).
- Retrieve information about the elements (tags or attributes) found in the document. (XMLData, XMLElementName, XMLParentName, XMLElementType).
- Modify the XML document (XMLAddAttribute, XMLAddChild, XMLInsertDocument, XMLInsertElement, XMLModify, XMLRename, XMLDelete).
- Execute an XPath query in an XML document (XMLExecuteXPath, XMLPath, XMLResult).
- Convert a character string from ANSI to XML and vice versa (TextToXML or XMLToText).
- Save the modifications if necessary (XMLBuildString and fSaveText).
- Close the XML document (XMLClose).
Remark: You also have the ability to create an XML document:
Unit examples (WINDEV): Reading and writing in XML format
Unit examples (WINDEV): XML parser
Training (WINDEV): WD Syntactic Coloring
Complete examples (WINDEV): WD Multimedia
This page is also available for…