1b Variables1b Variables
DPML By Example
Home > Books > Tutorials and Training Guides > DPML By Example > 1b Variables

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:


What's French for Variable?

Let's continue the innovative 'Hello World' theme we established in the previous section. But the web is multinational so let's I18Nize our outlook...

<idoc>
  <comment> *************************** DPML Tutorial - App2 Copy, Variable, Response *************************** </comment>
  <seq>
    <instr>
      <type>copy</type>
      <operand>ffcpl:/bonjour.xml</operand>
      <target>var:myHello</target>
    </instr>
    <instr>
      <type>copy</type>
      <operand>var:myHello</operand>
      <target>this:response</target>
    </instr>
    <instr>
      <type>cast</type>
      <operand>this:response</operand>
      <operator>
        <cast>
          <mimetype>text/html</mimetype>
        </cast>
      </operator>
      <target>this:response</target>
    </instr>
  </seq>
</idoc>

Try this application here

Variable *is* French for Variable

This application is not doing much more than the previous one. It copies a static resource ffcpl:/bonjour.xml to this:response. Only there's a twist or rather a pipeline. Instead of copying the resource directly to the response, the first instruction has a new target

<target>var:myHello</target>

This URI is a variable and is identified by the special scheme var:. A target which references a variable is the DPML method for creating a variable instance. The underlying DPML runtime takes care of managing the variable and maintaining it's URI name. Any subsequent instruction can use the variable as a general resource, as can be seen in the second instruction where the operand references the newly created var:myHello.

Therefore, in this application, the first instruction copies ffcpl:/bonjour.xml into a new variable var:myHello. The second instruction then copies the variable into this:response.

Putting it more formally

Variables have context level scope, meaning a variable is accessible from anywhere in the idoc subsequent to it's creation but variables cannot be accessed from another idoc or another instance of the same idoc - as we'll see later it is possible for an idoc to be accessed concurrently. Variables are automatically garbage collected upon the completion of the DPML instruction document. Lastly, as will be shown later, a variable can be both the operand and target of an instruction allowing a=f(a) style reassignments.

Summary

In this section we introduced variables and showed how they are created and how they can be used just like any other resource.

In the next section we give more details on this:response...

© 2003-2007, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.