|
|
|
|
- Presentación
- Ejemplo de uso
administración de XML: Ejemplo de uso
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": 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)
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|