Try OpenEdge Now
skip to main content
BPM Events User's Guide
XML messages : New syntax for iteration : Foreach syntax for iteration
 

Foreach syntax for iteration

The format of the foreach syntax is as follows:
<foreach> ::= ‘foreach’ <item_decl> (‘,’ <item_decl> )*
      [ ‘where’ <expr> ]
      ‘{‘ ( <statement> )* ‘}’
<item_decl> ::= <ID> [ ":" | "of" ] <expr>

Simple case

An example of a simple case of foreach usage is given below.
namespace po = "http://example.com/po";
foreach item of po *~ "po:purchaseOrder/po:itemsList/po:item[@a > 10]" {
      f(item1.a);
}

General case

An example of a general case of foreach usage is given below.
namespace po = "http://example.com/po";
val po = …;
val xml = …;
foreach item1 of po *~ "po:purchaseOrder/po:itemsList/po:item[@a > 10]",
      item2 of xml *~ "po:a/po:b[@x = ‘aa’]/po:e[@a > 10]"
where item1.a > item2.b
{        f(item1.a, item2.b);
}