Saltar al contenido principal
Versión: Siguiente

XML DOM

DOM Append XML child node ( refElement : Text ; tipoHijo : Integer ; valorHijo : any ) : Text
DOM Append XML element ( refElementTarget : Text ; refElementFuente : Text ) : Text
DOM CLOSE XML ( elementRef : Text )
DOM Count XML attributes ( elementRef : Text ) : Integer
DOM Count XML elements ( elementRef : Text ; nomElement : Text ) : Integer
DOM Create XML element ( elementRef : Text ; xRuta : Text {; nomAtrib : Text ; valorAtrib : Text, Boolean, Integer, Real, Time, Date} {; ...(nomAtrib : Text, valorAtrib : Text, Boolean, Integer, Real, Time, Date)} ) : Text
DOM Create XML element arrays ( refElement : Text ; xRuta : Text {; arrayNomsAtrib : Text array ; arrayValoresAtrib : Text array} {; ...(arrayNomsAtrib : Text array, arrayValoresAtrib : Text array)} ) : Text
DOM Create XML Ref ( raiz : Text {; nomEspacio : Text} {; nSNom : Text ; nSValor : Text} {; ...(nSNom : Text, nSValor : Text)} ) : Text
DOM EXPORT TO FILE ( elementRef : Text ; rutaArchivo : Text )
DOM EXPORT TO VAR ( elementRef : Text ; vXmlVar : Text, Blob )
DOM Find XML element ( elementRef : Text ; xRuta : Text {; arrRefElement : Text array} ) : Text
DOM Find XML element by ID ( elementRef : Text ; id : Text ) : Text
DOM Get first child XML element ( elementRef : Text {; nomElementHijo : Text {; valorElementHijo : any}} ) : Text
DOM Get last child XML element ( elementRef : Text {; nomElementHijo : Text {; valorElementHijo : any}} ) : Text
DOM Get next sibling XML element ( elementRef : Text {; nomElemHermano : Text {; valorElemHermano : any}} ) : Text
DOM Get parent XML element ( elementRef : Text {; nomElemPadre : Text {; valorElemPadre : any}} ) : Text
DOM Get previous sibling XML element ( elementRef : Text {; nomElemHermano : Text {; valorElemHermano : any}} ) : Text
DOM Get root XML element ( elementRef : Text ) : Text
DOM GET XML ATTRIBUTE BY INDEX ( elementRef : Text ; indexAtrib : Integer ; nomAtrib : Variable ; valorAtrib : Variable )
DOM GET XML ATTRIBUTE BY NAME ( elementRef : Text ; nomAtrib : Text ; valorAtrib : Variable )
DOM GET XML CHILD NODES ( refElement : Text ; ArrTiposHijos : Integer array ; arrRefsNodos : Text array )
DOM Get XML document ref ( refElement : Text ) : Text
DOM Get XML element ( elementRef : Text ; nomElement : Text ; indice : Integer ; valorElement : Variable ) : Text
DOM GET XML ELEMENT NAME ( elementRef : Text ; nomElement : Variable )
DOM GET XML ELEMENT VALUE ( elementRef : Text ; valorElement : Variable, Field {; cDATA : Variable, Field} )
DOM Get XML information ( elementRef : Text ; infoXML : Integer ) : Text
DOM Insert XML element ( refElementTarget : Text ; refElementFuente : Text ; indiceHijo : Integer ) : Text
[DOM Parse XML source ( doc : Text {; validacion : Boolean {; dtd
[DOM Parse XML variable ( variable : Blob, Text {; validacion : Boolean {; dtd
DOM REMOVE XML ATTRIBUTE ( refElement : Text ; nomAtrib : Text )
DOM REMOVE XML ELEMENT ( elementRef : Text )
DOM SET XML ATTRIBUTE ( elementRef : Text ; nomAtrib : Text ; valorAtrib : any {; ...(nomAtrib : Text ; valorAtrib : any)} )
DOM SET XML DECLARATION ( elementRef : Text ; codificacion : Text {; autonomo : Boolean {; indentacion : Boolean}} )
DOM SET XML ELEMENT NAME ( elementRef : Text ; nomElement : Text )
DOM SET XML ELEMENT VALUE ( elementRef : Text {; xRuta : Text}; valorElement : any {; *} )

Visión general de los comandos XML DOM

Consulte la sección XML, DOM y SAX para obtener una definición de XML DOM.

Creación, apertura y cierre de documentos XML mediante DOM

Los objetos creados, modificados o analizados por los comandos DOM de 4D pueden ser texto, URLs, documentos o BLOBs. Los comandos DOM utilizados para abrir objetos XML en 4D son DOM Parse XML source y 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.

Nota sobre el uso de parámetros BLOB XML: por razones históricas, los comandos XML como DOM Parse XML variable aceptan parámetros de tipo BLOB. Sin embargo, se recomienda encarecidamente almacenar las estructuras XML como texto. El uso de BLOBs está reservado al tratamiento de datos binarios. Conforme con las especificaciones XML, los datos binarios se codifican automáticamente en Base64, incluso cuando el BLOB contiene texto.

Soporte de la notación XPath

Varios comandos XML DOM (DOM Create XML element, DOM Find XML element, DOM Create XML element arrays y DOM SET XML ELEMENT VALUE) soportan algunas expresiones XPath para acceder a elementos XML.

La notación XPath procede del lenguaje XPath, diseñado para navegar dentro de estructuras XML. Permite fijar elementos directamente dentro de una estructura XML mediante una sintaxis de tipo "pathname", sin tener que indicar necesariamente la ruta completa para llegar a ella.

Por ejemplo, dada la siguiente estructura:

   <RootElement>
<Elem1>
<Elem2>
<Elem3 Font=Verdana Size=10> </Elem3>
</Elem2>
</Elem1>
</RootElement>

La notación XPath permite acceder al elemento 3 utilizando la sintaxis /RootElement/Elem1/Elem2/Elem3.

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.

Compatibilidad

A partir de 4D 18 R3, la implementación de XPath ha sido modificada para ser más compatible y soportar un conjunto más amplio de expresiones. Si desea beneficiarse de las funciones extendidas en sus bases de datos convertidas, deberá seleccionar la opción Utilizar XPath estándar de la Página de compatibilidad.

Gestión de errores

Muchas funciones de este tema devuelven una referencia a un elemento XML. Si se produce un error durante la ejecución de la función (por ejemplo, si la referencia al elemento raíz no es válida), la variable OK se pone en 0 y se genera un error.

Además, la referencia devuelta en este caso es una secuencia de 32 caracteres cero "0".