Bookmark and Share Share

<constructor>

This statement constructs a well-formed document, wrapped in a root node, and assigns it to an input or output parameter or to a variable. You define the structure as literal XML and assign static data or use dynamic mashup expressions to assign data dynamically.

Note: it is a good practice to use a separate namespace for the elements in the structure being constructed, so that they are clearly separated from EMML markup.

See Construct the Complete Document and Construct the Root and Append Repeated Content for examples of the two common patterns used with <constructor>.

Can Contain

Can contain text and any well-formed literal XML.

Allowed In mashup, else, elseif, for, foreach, if, macro, operation, sequence, while,

Attributes

Name Required Description
outputvariable yes

The required variable to accept the output of this statement.

<constructor> Examples

Construct the Complete Document

This is the basic use of <constructor> to define the entire contents of a variable. For example:

<mashup ... 
  xmlns:svc="http://www.someservices.com/services/catalogService" 
  xmlns:res="http://www.myCompany.com/myresults"> 
... 
<constructor outputvariable="result"> 
    <res:mailingList> 
      <res:displayName>{$filterResult/list/name}</res:displayName> 
      <res:email>{$filterResult/list/email}</res:email> 
    </res:mailinglist> 
</constructor> 
... 
<constructor outputvariable="$lookupItem"> 
  <svc:query> 
    <svc:account>{$acctId}</svc:account> 
    <svc:item> 
      <svc:itemnumber>{$itemId}</svc:itemnumber> 
      <svc:type>UPC</svc:type> 
      <svc:scope>global</svc:scope> 
    </svc:item> 
  <svc:query> 
</constructor>

The data to add can be literal text or Dynamic Mashup Expressions to add dynamic data.

Construct the Root and Append Repeated Content

If you need to fill a variable with a set of repeating data, you must still wrap this in a root node. To handle this scenario, you can use <constructor> to add the root node and <appendresult> to fill in content.

For example:

<mashup ... 
  xmlns:res="http://www.myCompany.com/myresults"> 
... 
<constructor outputvariable="$result"> 
  <res:comments/> 
</constructor> 
... 
<foreach variable="$comment" 
   items="$calls//customerCall/comment"> 
  <appendresult outputvariable="result"> 
  <res:comment> 
     <res:customer>{$comment//custom/name/string()}</res:customer> 
    <res:report>{$comment//description}</res:report> 
  </res:comment> 
  </appendresult> 
</foreach>