AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de archivos XML
  • Example for handling an XML file
XMLBuildString (Example)
Example for handling an XML file
WEBDEV - Código ServidorPHP
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")
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/05/2022

Señalar un error o enviar una sugerencia | Ayuda local