DynamicXmlBuilder Attributes

Node and Element Attributes

The examples we see on this page contain conventional xml nodes and text elements. If you want a node or an element to have attributes such as we see below in the <XELIG version="1.00"> node and the <exam programid="Annual" examid="ABC Level 3 Exam" /> element of the event subnode, then read on.


Please note that node and element attributes are available only in the August 2005 release and later.

Node Attributes

If you include in your node sql a column alias that contains the special characters ~nodeattribute~ along with the node name to the left of the characters and the attribute name to the right, then whatever is the value returned by that column alias will be set as an attribute value for that node. The characters ~nodeattribute~ are case sensitive and must be lower case. The node sql may return one or many column aliases with the same node name to the left of ~nodeattribute~ but with different attribute names to the right; this will add multiple attributes to the node.

For example, observe the following select statement in the node sql for the XELIG node name. We are returning a column alias called [XELIG~nodeattribute~version]:


This column alias will set an attribute for the XELIG node but it will not add an element in this node. Note that the characters to the left of the column alias with ~nodeattribute~ must be identical to the node name, which in this case also is XELIG. This is case sensitive as well.

Here is the XML Document returned. You will see that the XELIG node has an attribute called version, and the value of the attribute is 1.00.


Let’s look carefully at the column alias:

[XELIG~nodeattribute~version] = '1.00'

The value to the left of ~nodeattribute~ which is XELIG is used to link the attribute to the node. The value to right of ~nodeattribute~ which is version is the attribute name. The value that will be returned in the record set results of the query is ‘1.00’ which will become the attribute’s value.

Case Sensitivity

The following will not work because the node name is XELIG (all upper case) but the value of the column alias in the node sql is Xelig (only the first letter is upper case):


Element Attributes

Just as we see with Node Attributes above, element attributes may be added if you include a column alias in your node sql that contains the special characters ~attribute~ along with the element name to the left of ~attribute~ and the attribute name to the right. The value returned by this column alias will become the attribute’s value. As with node attributes, the node sql may return one or many column aliases with the same element name to the left of ~attribute~, but with different attribute names to the right; this will add multiple attributes to the same element.

For example, observe the exam element in the event node. It has two attributes, one for programid and another for examid.


Here is the node sql that generated this element:


In this example, the XmlNode will have one element for exam with two attributes, programid and examid. You may have as many attributes as necessary.

Look carefully at the following lines from the select statement in the node sql and observe how they drive the generation of the Xml element as shown in the XML underneath it:

[exam~attribute~programid] = 'ABC',
[exam~attribute~examid] = {_exam_id},
<exam   programid="ABC"   examid="ABC Level 3 Exam"   />

Additional Example of Element Attributes

Here is another example of element attributes. Notice how the member element has an attribute for id and name.


To return an xml document such as this, you include a column alias in your node sql a select statement such as this:

SELECT 
[member~attribute~id] = cst_id,
[member~attribute~name] = cst_sort_name_dn,
[user] = cst_add_user,
[added] = cst_add_date
FROM co_customer (nolock)

Note the alias names:

[member~attribute~id] = cst_id,
[member~attribute~name] = cst_sort_name_dn,

Combining Element Text and Attributes

An element may contain both text and attributes as shown in this Xml result:


Here is the node sql:


You will see that we have three column aliases related to product. The first is product without ~attribute~ and then we see the next two column aliases are for ~attribute~ related to the product element. The two attributes are code and key.

Setting Node Text Value

Feature available after August 2005 build

Suppose you want the following XML:


Within an <Individual> node, you want to have multiple <interest> nodes. To do this, in your node sql of the node definition you will use the special characters ~nodetext~ as shown:


Notice the first column alias is in the following format:

NameOfNode~nodetext~NameOfNode

You could combine this statement with node attributes to form this XML:


The node sql for the XML above is this:


Finally, you could output the XML this way:



The node sql for the XML above is:


Another alternate is to contain the <interest> nodes in a larger <Interests> node which is documented in the Hierarchical Container Nodes section of the main DynamicXmlBuilder article:


You will add the <Interests> node under the <Individual> node and then next the <interest> node under the <Interests> node.