ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / XML file functions
  • Overview
  • Importing an XSD file into a project
  • Using an imported description in the project
  • Example: Full creation of a file according to the XSD description given in example:
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
Overview
WINDEV, WINDEV Mobile and WEBDEV include several functions for handling the XML code. The XML code used must comply with the XML standard. For more details, see the documentation specific to XML. For more details on WLanguage functions, see XML.
WINDEV, WEBDEV and WINDEV Mobile allow you to import files in XSD format. An XSD file contains the description of the XML file of the same name. Knowing the structure of an XML document allows you to check the validity of this document. The description language for the content of an XSD document is also in XML format.
An example of XSD file:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="lastname" type="xsd:string"/>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="dob" type="xsd:date"/>
<xsd:element name="email" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Followed by a valid XML file:
<?xml version="1.0" encoding="UTF-8"?>
<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="person.xsd">
<lastname>Johnson</lastname>
<firstname>John</firstname>
<dob>1967-08-13</dob>
<email>test@yahoo.com</email>
</person>
Importing an XSD file into a project
To import an XSD file into a project:
  1. In the "Project explorer" pane, select "External descriptions".
  2. Right-click and select "Import an XSD into this project". The import wizard starts. You can:
    • Import an XSD file from the Internet.
    • Import a local XSD file.
  3. Specify the characteristics of the XSD file to be imported.
  4. Validate. The XSD file is automatically added in the project explorer ("External descriptions" branch). It is ready to use.
Caution:
  • To work at runtime, the XSD file must not be present in a subdirectory of the project or executable.
  • Only XSD files with schemas in version 1.0 are supported.
Using an imported description in the project
To use the description of the XML document, simply use the variables automatically generated by the import.
  1. Declare an XML document in the format of the imported description. For example, if the imported description is named 'person':
    cMyDoc is xmlDocument <description="person">

    Remark: You can specify the file extension during the declaration. For example:
    cMyDoc is xmlDocument <description="person.xsd">
  2. Initialize the different variables that are included in the description of the XML document. For example, if the document includes the last name and the first name of a person:
    cMyDoc.person.lastname = "MOORE"
    cMyDoc.person.firstname = "VINCE"

    Remarks:
    • Each element is separated by a dot ..
    • A help is proposed when entering the names of variables.
    • If the name of an element contains a special character (dash for example), it must be enclosed in simple quotes:
      cMyDoc.person.'id-person' = "ValueId"
  3. Several functions can be used to handle the XSD file in order to validate the description of the XML file:
    XMLSaveSaves an XML document in a file.
    XMLValidDocumentValidates an XML document from an XSD schema.
    XMLValidNodeValidates an XML node, its children and its attributes from its description in the XSD schema linked to the XML document.

Example: Full creation of a file according to the XSD description given in example:

cMyDoc is xmlDocument <description="person.xsd">
 
cMyDoc.person.lastname = "Moore"
cMyDoc.person.firstname = "Vince"
cMyDoc.person.dob = "19710211"
cMyDoc.person.email[1] = "vince.moore@mydomain.com"
cMyDoc.person.email[2] = "vince.moore@otherdomain.com"
 
XMLSave(cMyDoc, fExeDir() + ["\"] + "test.xml")
 
// Or with an intermediate check:
IF XMLValidDocument(cMyDoc) = True THEN
XMLSave(cMyDoc, fExeDir() + ["\"] + "test.xml")
IF ErrorOccurred = True THEN
Error("Unable to save the XML document", ErrorInfo())
ELSE
Info("OK", fExeDir() + ["\"] + "test.xml")
END
ELSE
Error("The XML document is invalid", ErrorInfo())
END
Minimum version required
  • Version 15
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/21/2023

Send a report | Local help