- 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:
<Variable name> is xmlDocument, description = <Document name>
<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 XML document directly from the "Project Explorer" pane.
- When using a sample document, you also have the ability to use the following syntax:
<Variable name> is xmlDocument
<Variable name> = XMLOpen(<Document name>)
- You can directly access the variable nodes by their names. These names are automatically proposed by the automatic completion mechanism 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 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
[ + ]
Using the XMLxxx functions to:
- Create an XML document
- Read an XML document
Unit examples (WINDEV): XML parser
[ + ]
Studying the content of an XML file via the XMLxxx functions of WINDEV
Training (WINDEV): WD Syntactic Coloring
[ + ]
This example proposes a base class used to perform a standard syntax highlighting on some text.
This highlighting is based on a rough analysis of the lemmes found in a text in order to identify the elements of a programming language for instance.
It can be overridden or derived in order to customize the system and the highlighting language.
This example is used to highlight SQL code and XML code but it can be extended to highlight other languages or other text formats.
Complete examples (WINDEV): WD Multimedia
[ + ]
This example shows how to play animations, audio and video files (MP3, WAV, AVI, MPEG, etc.) using the Multimedia control in WINDEV.
This page is also available for…