ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / XML file functions
  • Overview
  • Use 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
XML management: Use example
Overview
This application example manages an XML file named "Orders.xml". This file contains data regarding an order.
This example shows how to handle XML files using character strings.
Sample content of "orders.xml":
XML file
Use example
The following WLanguage code is used to:
  • create an XML document from the "Orders.XML" file:
    // Retrieve the XML content of "orders.xml" file
    MyXMLSource is string = fLoadText("C:\MyOrders\Orders.xml")
    // Create the XML document
    XMLDocument("XMLOrd", MyXMLSource)
    IF ErrorOccurred = True THEN
    Error("Error while creating the XML document")
    RETURN
    END
  • browse the XML document and retrieve the content of its elements:
    // Positions on the "" element
    XMLFirst("XMLOrd")
    // Moves one level down and positions on the "" element
    XMLChild("XMLOrd")
    // Retrieves the order number
    OrdNum is int = Val(XMLData("XMLOrd"))  // contains 1
    // Positions on the next element
    XMLNext("XMLOrd")
    // Retrieves the order date
    OrdDate is string = XMLData("XMLOrd")  // "11/20/2002"
  • find an element in the XML document and retrieve its content:
    // Find the product code
    XMLFind("XMLCde", "productcode", XMLTag + XMLCurrentLevel + XMLChildItem)
    IF XMLFound ("XMLCde") = True THEN
    PC is string = XMLData("XMLOrd") // contains "CDR-1080"
    END
  • add elements into the XML document:
    // Add a new order line
    XMLParent("XMLOrd")
    XMLParent("XMLOrd")
    XMLAddChild("XMLOrd", "orderline", "", True)
    XMLAddAttribute("XMLOrd", "number", "2")
     
    // Add the "productcode" tag
    XMLAddChild("XMLOrd", "productcode", "sro2125")
     
    // Add the "description" tag
    XMLAddChild("XMLOrd", "description", "optical mouse")
     
    // Add the "quantity" tag
    XMLAddChild("XMLOrd", "quantity", "15")
  • save the modifications made to the XML file:
    // Format the content of the XML document
    XMLFile is string = XMLBuildString("XMLOrd")
     
    // Save the XML file
    fSaveText("C:\MyOrders\Orders.xml", XMLFile)
  • close the XML document and display the result:
    //Close the document
    XMLClose("XMLOrd")
     
    // Display the data
    Info("Order Number: " + OrdNum, "Order date: " + OrdDate, "Product code: " + PC)
Minimum version required
  • Version 10
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help