Try OpenEdge Now
skip to main content
Working with XML
Writing XML Documents with the Simple API for XML (SAX) : Configuring a SAX-writer
 

Configuring a SAX-writer

Next, you configure the values that control how the write occurs. Below are some steps you might want to consider:
*If you are reusing a SAX-writer object for multiple writes, call the RESET method to clear the object and reset the default values.
*Use the SET-OUTPUT-DESTINATION method to declare the output destination and its type (file, longchar, memptr, stream).
*Set the VERSION, ENCODING, and STANDALONE attributes to ensure that the XML documents prolog is correctly configured.
*Set the FRAGMENT attribute if you are writing XML content that is not a complete XML document.
*Set the FORMATTED attribute if you want the XML output to have extra whitespace for easy readability.
*Set the STRICT attribute to FALSE if you do not want the write to fail if the parser detects invalid XML.
Here is an example:
DEFINE VARIABLE hSAXWriter AS HANDLE  NO-UNDO.
DEFINE VARIABLE lok        AS LOGICAL NO-UNDO.

CREATE SAX-WRITER hSAXWriter.
hSAXWriter:FORMATTED = TRUE.
lok = hSAXWriter:SET-OUTPUT-DESTINATION("file", "sw-example.xml").