Try OpenEdge Now
skip to main content
Working with XML
Writing XML Documents with the Simple API for XML (SAX) : Handling errors : Example of changing values in the WRITER-STATUS attribute
 

Example of changing values in the WRITER-STATUS attribute

Here is a code snippet (just the writer methods) that demonstrates the way the WRITER-STATUS changes:
                                             /* hSAXWriter:WRITE-STATUS */
/* SAX-WRITE-IDLE */
hSAXWriter:START-DOCUMENT( ). /* SAX-WRITE-BEGIN */
hSAXWriter:WRITE-COMMENT("comment"). /* SAX-WRITE-BEGIN */
hSAXWriter:START-ELEMENT("root", ""). /* SAX-WRITE-TAG */
hSAXWriter:START-ELEMENT("person", ""). /* SAX-WRITE-TAG */
hSAXWriter:START-ELEMENT("name", ""). /* SAX-WRITE-TAG */
hSAXWriter:WRITE-CHARACTERS("John"). /* SAX-WRITE-CONTENT */
hSAXWriter:END-ELEMENT("name", ""). /* SAX-WRITE-ELEMENT */
hSAXWriter:WRITE-EMPTY-ELEMENT("status", ""). /* SAX-WRITE-TAG */
hSAXWriter:INSERT-ATTRIBUTE("office", "1073"). /* SAX-WRITE-TAG */
hSAXWriter:END-ELEMENT("person", ""). /* SAX-WRITE-ELEMENT */
hSAXWriter:END-ELEMENT("root", ""). /* SAX-WRITE-ELEMENT */
hSAXWriter:END-DOCUMENT( ). /* SAX-WRITE-COMPLETE */
If STRICT is set to FALSE then calling a method while in the wrong state does not affect the XML document or the status of the writer. The method does not fail, the writer writes out the data, and the WRITE-STATUS is set accordingly. WRITE-STATUS is only set to SAX-WRITE-ERROR if there is a problem with the destination or proxml library at START-DOCUMENT.
If STRICT is set to TRUE then each of these invalid cases returns FALSE and an error message is generated:
<method_name> invalid while WRITE-STATUS is <state_name>.
In this case, the stream is closed and the WRITE-STATUS is change to SAX-WRITE-ERROR.
If there is a problem with the output destination or the proxml library, the WRITE-STATUS is set to SAX-WRITE-ERROR regardless of the setting of STRICT. One of the following error messages is generated:
Unable to write to output destination.
Or. . .
The proxml.dll or libproxml.so was missing or incomplete or XML could not be initialized.