IO and Variables

[Previous] [Next]

OmniMark has three keywords that assign data to a destination: set, output, and put. Set is the only keyword that you can use with numeric data types. With stream variables, however, you can use all three. Stream variables serve as both output conduits and string variables. When used as string variables, stream variables are actually acting as conduits to buffers, which OmniMark treats as data sources and destinations like any other stream.

The output keyword sends data to a stream that has been opened with open and made part of the current output with using output as.

The put keyword works like the using output as control structure, allowing you to change the current output and create output in a single action.

The set keyword performs the functions of both open and using output as: it opens a stream, makes it current output, and outputs to it in a single operation. This means that, as far as streams are concerned, there aren't different keywords for dealing with variables and external data sources, but instead there are a selection of keywords that you can use as appropriate on either variables or external data sources. For example, you can use the set action to place a simple value into a file.

 set file "duckbar.txt" to "A duck walks into a bar." 

Likewise, you can use open, put, and close to set the value of a variable.

 local stream Duck open Duck as buffer put Duck "A duck walks into a bar." close Duck 

The virtue of using the longer syntax is that you can write to the stream many times before closing it. This approach is much easier and more efficient than building up a string by a series of concatenations. Thus you can replace code like this:

 set Duck to "A duck walks into a bar" set Duck to Duck || "The bartender says, 'We don't serve ducks here'" set Duck to Duck || "The duck says, 'That's OK, I don't like duck anyway.'" set Duck to Duck || "'How about a beer?'" 

with code like this:

 open Duck as buffer using output as Duck do output "A duck walks into a bar" output "The bartender says, 'We don't serve ducks here'" output "The duck says, 'That's OK, I don't like duck anyway.'" output "'How about a beer?'" done 

This is an enormously powerful feature of OmniMark that enables you to choose the type of data-assignment mechanism appropriate to the scale of the operation you want to perform. You can use set for any kind of small-scale assignment, whether to a file or a variable, without the bother of opening files or buffers. For large-scale operations, you can use output with any file or stream variable and perform multiple updates without the need to specify the destination or even worry about the kind of destination involved. Choosing the mechanism appropriate to the scale of the operation you are performing will greatly simplify your code.

You must close a stream before it can be read or output:

 open Duck as buffer put Duck "A duck walks into a bar." close Duck output Duck 

You can use the action reopen to reopen a closed stream with its original content. However, if you use open to open the stream again, you'll lose the existing content:

 open Duck1 as buffer open Duck2 as buffer put Duck1 "A duck walks into a bar." put Duck2 " A duck walks into a bar." close Duck1 close Duck2 reopen Duck1 open Duck2 put Duck1 "He walks up to the bartender" put Duck2 "He walks up to the bartender" 

The preceding code will leave the stream Duck1 containing both lines, but Duck2 will contain only "He walks up to the bartender".



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net