|
|
|
|
|
- Declaring an xmlDocument variable
- Properties specific to the xmlDocument variables
- Using the indirection on the paths in an XML document
- Functions that use xmlDocument variables
xmlDocument (Type of variable) In french: xmlDocument (Type de variable)
The xmlDocument type is used to handle an XML file. The characteristics of this file can be defined and changed 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.
// Example that uses the following XML file: play.xml // <?xml version="1.0"?> // <PLAY> // <TITLE>Title of the play</TITLE> // // <PERSONAE> // <PERSONA>A character</PERSONA> // </PERSONAE> // // <ACT> // <SCENE> // <SPEAKER></SPEAKER> // <LINE></LINE> // </SCENE> // </ACT> // </PLAY> Â // Declare an xmlDocument variable that is using a document template RomeoAndJuliet is xmlDocument, description = "play.xml" Â // Load an XML document from a file RomeoAndJuliet = XMLOpen("romeo_and_juliet.xml", fromFile) Â // Display the version number of the XML Trace(RomeoAndJuliet..Version) Â // Display the title of the play by accessing the nodes directly Trace(RomeoAndJuliet.PLAY.TITLE)
Remarks 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: - 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). Remarks: - 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.
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 xmlDocument variables The following properties can be used to handle an xmlDocument variable: | | | Name | Type used | Effect |
---|
Encoding | Character string | Encoding 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. | RootNode | Array of xmlNode | Array 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. | Version | Character string | Version of the XML format. In most cases, this property is set to "1.0". |
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. Example: sXMLDoc is string = [ <?xml version="1.0" encoding="UTF-8"?> <Document> <VersionInfo> <Version>21</Version> <Year>2016</Year> </VersionInfo> </Document> ] Â xmlExample is xmlDocument = XMLOpen(sXMLDoc, fromString) Â sParam is string = "WINDEV_Param" Â // Direct reading of information ... Trace(xmlExample.Document.VersionInfo.Version) Â // Reading with part of XML path found in a variable // (idem if file item, window parameter, method, ...) sParameter is string = "VersionInfo" Trace({"xmlExample.Document." + sParameter + ".Version"}) Functions that use xmlDocument variables Note: The browse of an XMLDocument variable must be performed by using the FOR EACH syntax. XMLRead must not be used.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|