XML DOM
Visión general de los comandos XML DOM
See XML, DOM, and SAX section for a definition of XML DOM.
Creación, apertura y cierre de documentos XML mediante DOM
Objects created, modified or parsed by the 4D DOM commands can be text, URLs, documents or BLOBs. The DOM commands used for opening XML objects in 4D are DOM Parse XML source and DOM Parse XML variable.
Muchos comandos permiten leer, analizar y escribir los elementos y atributos. Los errores se recuperan utilizando el comando XML GET ERROR. No olvide llamar al comando DOM CLOSE XML para cerrar la fuente al final.
Note about use of XML BLOB parameters: For historical reasons, XML commands such as DOM Parse XML variable accept BLOB type parameters. However, it is highly recommended to store XML structures as Text. The use of BLOBs is reserved for processing binary data. In conformity with XML specifications, binary data are automatically encoded in Base64, even when the BLOB contains text.
Soporte de la notación XPath
Several XML DOM commands (DOM Create XML element, DOM Find XML element, DOM Create XML element arrays and DOM SET XML ELEMENT VALUE) support some XPath expressions for accessing XML elements.
La notación XPath procede del lenguaje XPath, diseñado para navegar dentro de estructuras XML. It allows the setting of elements directly within an XML structure via a "pathname" type syntax, without necessarily having to indicate the complete pathname in order to reach it.
Por ejemplo, dada la siguiente estructura:
<RootElement>
<Elem1>
<Elem2>
<Elem3 Font=Verdana Size=10> </Elem3>
</Elem2>
</Elem1>
</RootElement>
XPath notation allows you to access element 3 using the /RootElement/Elem1/Elem2/Elem3 syntax.
4D también acepta elementos XPath indexados utilizando la sintaxis Element[ElementNum]. Por ejemplo, dada la siguiente estructura:
<RootElement>
<Elem1>
<Elem2>aaa</Elem2>
<Elem2>bbb</Elem2>
<Elem2>ccc</Elem2>
</Elem1>
</RootElement>
La notación XPath permite acceder al valor "ccc" utilizando la sintaxis /RootElement/Elem1/Elem2[3].
Para una lista completa de expresiones XPath soportadas, consulte la descripción del comando DOM Find XML.
Starting with 4D 18 R3, the XPath implementation has been modified to be more compliant and to support a wider set of expressions. If you want to benefit from the extended features in your converted databases, you need to select the Use standard XPath option of the Compatibility page.
Gestión de errores
Muchas funciones de este tema devuelven una referencia a un elemento XML. If an error occurs during function execution (for example, if the root element reference is not valid), the OK variable is set to 0 and an error is generated.
In addition, the reference returned in this case is a sequence of 32 zero "0" characters.