contentsconceptssyntaxlibrariessampleserrorsindex
Full text search
Output
    Related Syntax  

All output from an OmniMark program goes to OmniMark's built-in current output. You do not usually need to explicitly state where you want output to go, you just output it and it goes to current output. When you do state a destination for output, you are, in effect, resetting current output to the named destination and outputting to current output.

You can change the destination of current output within a rule:

  element lamb
     local stream mary
     open mary as file "mary.txt"
     using output as mary
     do
        output "ba ba ba %c"
     done

This rule temporarily changes the current output to the file mary.txt. Any output that occurs in the do...done block following using output as goes to the new destination. Once the block is finished, current output reverts to its original destination. Note, however, that the output statement contains the parse continuation operator (%c). Is the new output destination in effect for all the processing that occurs as part of the parsing of the lamb element? Yes it is. Output that is generated by any rules that fire as a result of parsing the lamb element will go to the file "mary.txt".

To understand how this works, consider an XML file, "mary.xml", that contains a valid DTD and the following markup:

  <line>
  <person>Mary</person> had a little <person>lamb</person>
  </line>

And consider the following OmniMark program:

  global stream words
  global stream people

  process
     open words as file "words.txt"
     open people as file "people.txt"
     using output as words
     do xml-parse document
        scan file "mary.xml"
        output"%c"
     done

  element line
     output "%c"

  element person
     using output as people
     do
        output "%c "
     done

Running this program will leave you with two files: words.txt will contain " had a little ", and people.txt will contain "Mary lamb ". Look closely at this code to make sure you understand which output destination is in effect in the "line" element rule. Make sure you understand why the output ended up in the files it did. If you are comfortable with this, you know most of what you need to know about how OmniMark handles output.

The last rule of the program above can be shortened slightly by using put as a shorthand for the using output as block:

  element person
     put people "%c "

OmniMark's current output is a powerful mechanism for simplifying code by eliminating the need to always state where output is going. Once the destination of the current output is set, all output goes to that destination unless you explicitly send it elsewhere. Current output has the additional feature of being able to have more than one destination at a time:

  global stream my-file
  global stream my-buffer

  process
     open my-file as file "myfile.txt"
     output-to my-file
     submit "Mary had a little lamb"

  find "had"
     open my-buffer as buffer
     output using my-buffer and #current-output
     do
        output "I've been had!"
     done

This code will place "I've been had!" in both the file myfile.txt and in the variable my-buffer. #current-output stands for all the current destinations of current output, so you can use it to add a new destination to all those currently active (even if you don't know what they are).

      Related Syntax
   open
   output
   output-to
   put
   using output as
 
----

Top [CONTENTS] [CONCEPTS] [SYNTAX] [LIBRARIES] [SAMPLES] [ERRORS] [INDEX]

Generated: April 21, 1999 at 2:00:50 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © OmniMark Technologies Corporation, 1988-1999.