ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / XML file functions
  • Example for handling an XML file
XMLBuildString (Example)
Example for handling an XML file
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)PHP
sMyXMLDoc is string = "XML"
sXMLInfo is string // Result string
nIndex is int
nXMLPosition is int
 
XMLDocument(sMyXMLDoc, "") // Creates a blank XML document
 
// Invoice 1
// ----------
XMLAddChild(sMyXMLDoc, "LIST_OF_INVOICES", "", True) // Root element
XMLAddChild(sMyXMLDoc, "INVOICE", "", True)  // "Parent" node
 
// Information about the invoice
XMLAddChild(sMyXMLDoc, "NUMBER", NumToString(123))
XMLAddChild(sMyXMLDoc, "TOTAL", NumToString(420.50))
XMLAddChild(sMyXMLDoc, "VAT", NumToString(19.6))
XMLAddChild(sMyXMLDoc, "NOTES", "Information about invoice 123")
 
// Details of INVOICE lines:
FOR nIndex = 1 TO 5
XMLAddChild(sMyXMLDoc, "INVOICE_LINE", NumToString(nSubscript), True)
XMLAddChild(sMyXMLDoc, "DESCRIPTION", "Description line " + nSubscript)
XMLAddChild(sMyXMLDoc, "AMOUNT", NumToString(84.25))
// Moves one level up for the next line (or for the rest)
XMLParent(sMyXMLDoc)
END
 
// Invoice 2
// -----------
XMLParent(sMyXMLDoc)
 
// Moves one level up to be on the same level as the previous invoice
// OR XMLRoot(sMyXMLDoc) because there is only one level
XMLAddChild(sMyXMLDoc, "INVOICE", "", True)  // "Parent" node
XMLAddChild(sMyXMLDoc, "NUMBER", NumToString(456))
 
// Information about the invoice
XMLAddChild(sMyXMLDoc, "TOTAL", NumToString(420.50))
XMLAddChild(sMyXMLDoc, "VAT", NumToString(5.5))
XMLAddChild(sMyXMLDoc, "NOTES", "Information about invoice 456")
 
// Details of INVOICE lines:
FOR nIndex = 1 TO 10
// Saves the current position
nXMLPosition = XMLSavePosition(sMyXMLDoc)
XMLAddChild(sMyXMLDoc, "INVOICE_LINE", NumToString(nSubscript), True)
XMLAddChild(sMyXMLDoc, "DESCRIPTION", "Description line " + nSubscript)
XMLAddChild(sMyXMLDoc, "AMOUNT", NumToString(42.5))
// Other method in relation to XMLParent
// Restores the position for the next line (or for the rest)
XMLRestorePosition(sMyXMLDoc, nXMLPosition)
END
 
sXMLInfo = XMLBuildString(sMyXMLDoc)  // Retrieves the XML that was built
XMLClose(sMyXMLDoc) // Frees the XML document
 
// Create the XML file
fSaveText(CompleteDir(fExeDir()) + "Invoice.xml", sXMLInfo)
// Display in the application associated with XML
ShellExecute(CompleteDir(fExeDir()) + "Invoice.xml")
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help