KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Understanding how the command DOM Create XML element arrays works
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: February 8, 2012

In 4D v12 is a new command DOM Create XML element arrays. The really nice feature of this command is that it supports the setting of an element attributes in "paired" arrays, the attribute names in one array and the attribute value in the paired array. This is very efficient when programmatically creating several DOM elements that has numerous attributes.

It is not uncommon for DOM element attributes of a to be used to store values that one would expect to be stored as the element value. The advantage of this technique is that many values can be stored in one element and easily accessed individuality.

DOM Create XML element arrays creates as many DOM elements as there are elements in the paired arrays. Each DOM element created is assigned one element out of each array. Said differently, if there are five elements in the paired arrays, there will be five DOM elements created with the first DOM element receiving the array element number one of each paired array.

With the feature of using arrays to set the DOM element attributes, it would be easy to assume that the DOM elements would be created in the same index order of the arrays. Then based on that assumption using command DOM Get XML element ( elementRef ; elementName ; index ; elementValue ) -> Function result, which depends on the index parameter, would retrieve the elements in the order that the original paired arrays. This is not how the DOM elements are created in actuality!

Prior to creating the DOM elements, internally 4D sorts the paired arrays based on the attribute names of the first paired arrays passed to the command DOM Create XML element arrays. Given this fact, if the need is to retrieve the elements in the order of the original attribute arrays, it is necessary to create the attribute names in an alphabetical sorted order so that they will be returned in the order expected.