CreateElement Method (XDATA)
9.8A
The CreateElement method generates an element node at a specified position. The method uses the following format:
|
|
|
|
|
|
|
|
|
|
|
|
Where:
Flags Affected: EOS, OVER, ZERO
Note the following:
After the create operation, the node tree position does not move to the newly created node unless the OPTIONS parameter is used.
The ZERO flag is set if the {return} value is zero.
The OVER flag is set TRUE if the {return} variable is too small where the returned value is truncated.
The EOS flag is always cleared.
The {position} values are defined as follows:
|
Keyword |
Value |
Meaning... |
|
CREATE_AS_CURRENT_NODE |
0 |
Replace the current node. |
|
CREATE_AS_PARENT_NODE |
1 |
Insert node as the parent. |
|
CREATE_AS_FIRST_CHILD |
2 |
Insert node as first child node. |
|
CREATE_AS_LAST_CHILD |
3 |
Insert node as last child node. |
|
CREATE_AS_PREVIOUS_SIBLING |
4 |
Insert node as previous sibling node. |
|
CREATE_AS_NEXT_SIBLING |
5 |
Insert node as next sibling node. |
The *OPTIONS {mask} values are defined as follows:
|
Value |
Description |
|
0x1 |
This bit value causes the current node tree position to be changed to the newly created node position of the attribute. See the MOVE_TO_CREATE_NODE value. |
The {return} value is a zero if the method execution is successful. Otherwise, a non-zero value is returned to indicate an error has occurred. See the XDATA Method Return Values for more details.
This method can return these values:
|
Value |
Meaning |
|
0 |
XDATA_ERR_NONE (Success) |
|
1 |
XDATA_ERR_NO_MEM |
|
2 |
XDATA_ERR_INVALID_POSITION_TYPE |
|
11 |
XDATA_ERR_INVALID_POSITION |
If the {text} parameter and the JSON {type} parameters are not being used, the default method behavior when outputting a JSON document is to generate a JSON object.
If the parent of the created element has a JSONTYPE of JSON_TYPE_ARRAY, then a special label prefix of 'object' can be used when creating a JSON_TYPE_OBJECT to prevent the label from being output in the JSON array object elements. See Example 5.
Examples:
Example of CreateElement method for JSON or XML:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In this example code , the following simple JSON object string is created by the previous XDATA CreateElement methods
In this case, the "employee" is a JSON object with two JSON fields named "firstName" and "lastName". These JSON fields have a value that is a JSON string.
In this example code, the following simple XML string is created by the previous XDATA CreateElement methods:
Example of CreateElement method for JSON or XML when no {text} or JSON {type} parameters are used. In this example, all of the elements are defaulting to a JSON_TYPE_OBJECT.
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
In this example code , the following simple JSON object string is created by the previous XDATA CreateElement methods where the "firstName" and the "lastName" are JSON objects that are empty.
In this case, the "employee" is a JSON object with two JSON fields named "firstName" and "lastName". These JSON fields have a value that is an empty JSON object.
In this example code, the following simple XML string is created by the previous XDATA CreateElement methods.
Example of CreateElement method for JSON or XML for array output:
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In this example code , the following simple JSON object string is created by the previous XDATA CreateElement methods to output a JSON array.
In this case, the "employee" is a JSON array with two array JSON object elements.
In this example code, the following simple XML string is created by the previous XDATA CreateElement methods
This example shows an 'employees' JSON array that contains JSON objects for each 'Employee':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In this example code , the following simple JSON object string is created by the previous XDATA CreateElement methods to output a JSON array where each array element has the "Employee" label name.
In this case, the "employees" is a JSON array with one JSON object element that has the "Employee" label.
This example shows an 'employees' JSON array that contains JSON objects where each JSON object element DOES NOT have an "Employee" label reference:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ||
|
| ||
|
| ||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In this example code, the following simple JSON object string is created by the previous XDATA CreateElement methods to output a JSON array where each array element object does not have the "Employee" label name.
In this case, the "employees" is a JSON array with one JSON object element that does not have an "Employee" label.
See Also: XDATA, XDATA Methods, Method Syntax
![]() |