AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de archivos XML
  • Presentación
  • Ejemplo de uso
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Otros
Procedimientos almacenados
administración de XML: Ejemplo de uso
Presentación
Este ejemplo de aplicación gestiona un archivo XML llamado "Orders.xml".. Este archivo contiene datos sobre un pedido.
Este ejemplo muestra cómo manipular archivos XML utilizando cadenas de caracteres.
Ejemplo de contenido de "orders.xml":
Archivo XML
Ejemplo de uso
El siguiente código WLanguage se utiliza para:
  • crear un Document XML a partir del archivo "Orders.XML":
    // 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
  • navegar por el XML Document y recuperar el contenido de sus elementos:
    // 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"
  • encontrar un elemento en el Document XML y recuperar su contenido:
    // Find the product code
    XMLFind("XMLCde", "productcode", XMLTag + XMLCurrentLevel + XMLChildItem)
    IF XMLFound ("XMLCde") = True THEN
    PC is string = XMLData("XMLOrd") // contains "CDR-1080"
    END
  • añadir elementos en el 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")
  • guardar las modificaciones realizadas en el archivo XML:
    // Format the content of the XML document
    XMLFile is string = XMLBuildString("XMLOrd")

    // Save the XML file
    fSaveText("C:\MyOrders\Orders.xml", XMLFile)
  • cerrar el Document XML y mostrar el resultado:
    //Close the document
    XMLClose("XMLOrd")
     
    // Display the data
    Info("Order Number: " + OrdNum, "Order date: " + OrdDate, "Product code: " + PC)
Versión mínima requerida
  • Versión 10
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