Saltar para o conteúdo principal
Versão: Próximo

XML DOM

DOM Append XML child node ( refElemento : Text ; tipoFilho : Integer ; valorFilho : Text, Blob ) : Text
DOM Append XML element ( refElementoTarget : Text ; refElementoFonte : Text ) : Text
DOM CLOSE XML ( refElemento : Text )
DOM Count XML attributes ( refElemento : Text ) : Integer
DOM Count XML elements ( refElemento : Text ; nomeElemento : Text ) : Integer
DOM Create XML element ( refElemento : Text ; xRota : Text {; nomeAtrib : Text ; valorAtrib : Text, Boolean, Integer, Real, Time, Date} {; ...(nomeAtrib : Text, valorAtrib : Text, Boolean, Integer, Real, Time, Date)} ) : Text
DOM Create XML element arrays ( arrayNomesAtrib : Text ; xRota : Text {; atribNomesArray : Text array ; atribValoresArray : Text array} {; ...(atribNomesArray : Text array, atribValoresArray : Text array)} ) : Text
DOM Create XML Ref ( raiz : Text {; nomeEspaço : Text} {; nSNome : Text ; nSValor : Text} {; ...(nSNome : Text, nSValor : Text)} ) : Text
DOM EXPORT TO FILE ( refElemento : Text ; viaArquivo : Text )
DOM EXPORT TO VAR ( refElemento : Text ; vXMLVar : Text, Blob )
DOM Find XML element ( refElemento : Text ; xPath : Text {; arrRefElementos : Text array} ) : Text
DOM Find XML element by ID ( refElemento : Text ; id : Text ) : Text
DOM Get first child XML element ( refElemento : Text {; nomElemFilho : Text {; valorElemFilho : Text}} ) : Text
DOM Get last child XML element ( refElemento : Text {; nomElemFilho : Text {; valorElemFilho : Text}} ) : Text
DOM Get next sibling XML element ( refElemento : Text {; nomeElemIrmao : Text {; valorElemIrmao : Text}} ) : Text
DOM Get parent XML element ( refElemento : Text {; nomeElemPai : Text {; valorElemPai : Text}} ) : Text
DOM Get previous sibling XML element ( refElemento : Text {; nomeElemIrmao : Text {; valorElemIrmao : Text}} ) : Text
DOM Get root XML element ( refElemento : Text ) : Text
DOM GET XML ATTRIBUTE BY INDEX ( refElemento : Text ; indexAtrib : Integer ; nomeAtrib : Variable ; valorAtrib : Variable )
DOM GET XML ATTRIBUTE BY NAME ( refElemento : Text ; nomeAtrib : Text ; valorAtrib : Variable )
DOM GET XML CHILD NODES ( elemRef : Text ; arrTiposFilhos : Integer array ; arrRefsNodos : Text array )
DOM Get XML document ref ( arrayNomesAtrib : Text ) : Text
DOM Get XML element ( refElemento : Text ; nomeElemento : Text ; index : Integer ; valorElemento : Variable ) : Text
DOM GET XML ELEMENT NAME ( refElemento : Text ; nomeElemento : Variable )
DOM GET XML ELEMENT VALUE ( refElemento : Text ; valorElemento : Variable {; cDATA : Variable} )
DOM Get XML information ( refElemento : Text ; xmlInfo : Integer ) : Text
DOM Insert XML element ( tarfetElementRef : Text ; sourceElementRef : Text ; childIndex : Integer ) : Text
[DOM Parse XML source ( documento : Text {; validaçao : Boolean {; dtd
[DOM Parse XML variable ( variável : Blob, Text {; validaçao : Boolean {; dtd
DOM REMOVE XML ATTRIBUTE ( elementoRef : Text ; nomeAtrib : Text )
DOM REMOVE XML ELEMENT ( refElemento : Text )
DOM SET XML ATTRIBUTE ( refElemento : Text ; nomeAtrib : Text ; valorAtrib : Text, Boolean, Integer, Real, Time, Date {; ...(nomeAtrib : Text, valorAtrib : Text, Boolean, Integer, Real, Time, Date)} )
DOM SET XML DECLARATION ( refElemento : Text ; codificaçao : Text {; autonomo : Boolean {; recuo : Boolean}} )
DOM SET XML ELEMENT NAME ( refElemento : Text ; nomeElemento : Text )
DOM SET XML ELEMENT VALUE ( refElemento : Text {; xRota : Text}; valorElemento : Text, Variable {; *} )

Overview of XML DOM Commands

See XML, DOM, and SAX section for a definition of XML DOM.

Creating, opening and closing XML documents via 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.

Many commands then let you read, parse and write the elements and attributes. Errors are recovered using the XML GET ERROR command. Do not forget to call the DOM CLOSE XML command to close the source in the end.

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.

Support of XPath notation

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.

XPath notation comes from the XPath language, designed to navigate within XML structures. 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.

For example, given the following structure:

   <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 also accepts indexed XPath elements using the Element[ElementNum] syntax. For example, given the following structure:

   <RootElement>
<Elem1>
<Elem2>aaa</Elem2>
<Elem2>bbb</Elem2>
<Elem2>ccc</Elem2>
</Elem1>
</RootElement>

XPath notation allows you to access the "ccc" value using the /RootElement/Elem1/Elem2[3] syntax.

For a comprehensive list of supported XPath expressions, refer to the DOM Find XML element command description.

Compatibidade

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.

Error Handling

Many functions in this theme return an XML element reference. 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.