Latest News

the latest news from our team

Create XML Action in eFORMz

This document expands on the Create XML post by going through a sample eFORMz project. The concepts illustrated by the project also apply to the “Record Element” output type.

Sample project: CreateXMLRepeatingNode.efz

Create XML with Singleton Variable

The ArrayVar3 variable is a repeating variable with 3 instances, and SingletonVar is a singleton variable with only one instance.

In the “Create XML with Singleton Try 1” procedure, we use the “Create XML” action to create an XML element that repeats on ArrayVar3. Then inside this node, we create two subnodes: ArrayVar3Node to hold the individual values of ArrayVar3, and SingletonVarNode to hold the value of the SingletonVar. We assign the XML thus created to the XMLVersion1 variable.

Inspecting the XMLVersion1 variable, we see the XML only shows the value of the single variable SingletonVar one time, in the first instance of the SingletonVarNode node:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
  <RepeatingNode>
    <ArrayVar3Node>0</ArrayVar3Node>
    <SingletonVarNode>SingletonVarValue</SingletonVarNode>
  </RepeatingNode>
  <RepeatingNode>
    <ArrayVar3Node>1</ArrayVar3Node>
    <SingletonVarNode />
  </RepeatingNode>
  <RepeatingNode>
    <ArrayVar3Node>2</ArrayVar3Node>
    <SingletonVarNode />
  </RepeatingNode>
</Root>

Create XML with Repeated Singleton Variable

If we want the value of the SingletonVar to repeat, we must create a repeating variable and set the value of each instance to the singleton value. This is illustrated by the procedures “Create Variable that repeats the Singleton Value” and “Initialize SingletonVarRepeating”. The former uses the “Load Variable from Variable” action to create a repeating variable, SingletonVarRepeating, that has the same number of instances as the ArrayVar3 variable. Then the latter procedure loops through that variable, setting each instance to the singleton value “SingletonVarValue”.

Finally, the procedure “Create XML with Singleton Try 2” uses the Create XML action to create XML where both the array variable and the singleton variable have their values repeated in all the repeating elements. This XML is saved in the variable XMLVersion2, shown here:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
  <RepeatingNode>
    <ArrayVar3Node>0</ArrayVar3Node>
    <SingletonVarNode>SingletonVarValue</SingletonVarNode>
  </RepeatingNode>
  <RepeatingNode>
    <ArrayVar3Node>1</ArrayVar3Node>
    <SingletonVarNode>SingletonVarValue</SingletonVarNode>
  </RepeatingNode>
  <RepeatingNode>
    <ArrayVar3Node>2</ArrayVar3Node>
    <SingletonVarNode>SingletonVarValue</SingletonVarNode>
  </RepeatingNode>
</Root>

Record Element with XML Content

The Record Element output is created with a root node “Root” and two child nodes “BadNode” and “GoodNode”. We set the value of the BadNode node with the contents of the variable XMLVersion1, indicating in the “Element Content” dialog that the format should be “XML” and to “Omit root”:

This demonstrates how we can take an existing XML string and add it into either Create XML or Record Element as the value of a node, effectively grafting the XML represented by that XML string into the XML structure.
Similarly, we set the value of the GoodNode node with the contents of the variable XMLVersion2:

Examining Output XML

The contents of the Record Element are displayed in the Viewer window, so you can see that in the “BadNode” the singleton variable value is only shown in the first instance of the RepeatingNode, while in the “GoodNode” the singleton variable value is shown in all the instances:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code