XML Processing using the Whitebeam Environment

Site Map
 
Home
 
Application Guide
  Quick Start
  PHP and ASP
  Writing Apps
  Applications
  Tutorials
    Replication
    Postgres Interface
    XML Processing
      Introduction
      Overview
      Processing Data
      The XML JavaScript API
      Special Behaviour
      Manual Execution
      XML Macros
      Example
    Using XPath
    Binary Object
    Using HttpRequest
    SmtpRequest
    Session
    Meta Data
    Iterators
    Memb Services
    Page Look&feel
    Authentication+
    Questionnaires
    Message Groups
    Form Handling
  Samples
Reference
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

XML Processing using the Whitebeam Environment

Manually Executing XML Subtrees

The XML tree built with the XmlParser.build is generally 'executed' in order to populate the 'output' area of each element. It is not 'required' that you execute the XML - there are applications that may just require the basic structure of the tree.

At any time the output area may contain different things:

  • If the tag has yet to be executed the output area will be empty.
  • If it has been executed then it will contain the contents from that execution.

  • A tag tree can be executed multiple times in order to produce different output. At any time the 'output' area of an element contains the text from the last execution of that element.

You can see from the description of the rb:block tag above that initially the output areas of all children of the block will be empty. In JavaScript you can however get hold of the sub-tree of the rb:block tag and execute it. To do this give the block tag an id (using the rb:id attribute). This is illustrated below:

<rb:block rb:id="myBlock">
   <tr>
      <td>
         <rb:eval expr="prop">
      </td>
      <td>
         <rb:eval expr="object[prop]">
      </td>
   </tr>
</rb:block>

This example block is labeled - so we can find it - it has an 'id' and so we can simply search for the element with the XmlTag.findId method on the root of the tree. eg:

<rb:script>
   var tag = rb.xml.root.findId("myBlock")
</rb:script>

Remember at this stage these tags have never been executed! If you now call 'var text=tag.bodytext()' the result will be an empty string. To generate output you have to first execute the tag. Do this using the tag.execute() method. The normal behaviour of this method is to run the tag on which it is invoked. An exception occurs where the tag is an 'rb:block' tag - because the effect of that tags execute is to do nothing! In the case of an rb:block tag all of the children of the tag are executed. This will effectively populate the output areas of each of the children. Note that in the example above the block contains active server-side behaviour in the form of <rb:eval...> tags. The block can be used in a loop to dump the contents of an object's properties:

<rb:script>
   var object = new Object;
   object.name = "Peter";
   object.sname = "Wilson";

   var prop, testObj;
   var tag = rb.xml.root.findId("myBlock")

   rb.page.write('<table border="1">');
   for (var prop in object) {
      // generate new output for this row.
      tag.execute();

      // Now output to the client (adds to my output area).
      rb.page.write(tag.bodytext());
   }
   rb.page.write('</table>');
</rb:script>

Whitebeam release 1.3.36
(loadtime : 20ms)