Try OpenEdge Now
skip to main content
Working with XML
Writing XML Documents with the Simple API for XML (SAX) : Handling errors : How errors are handled when STRICT is TRUE
 

How errors are handled when STRICT is TRUE

If STRICT is set to TRUE, then the writer will validate the structure of the XML document as it writes it out. With this attribute, the SAX-writer attempts to keep the developer from creating invalid XML documents. It does this by ensuring that the methods are called in correct order.
If SAX-writer finds an incorrect method call:
*The method fails and returns FALSE
*It generates an error message
*The SAX-writer changes the WRITE-STATUS to SAX-WRITE-ERROR
*The SAX-writer closes the document stream
The following table describes the conditions that generate an error message when STRICT is set to TRUE.
Table 17. Common error messages
Methods effected
Description
All
If a particular method is called when the WRITE-STATUS attribute status value is an illegal value for the method, the method fails and generates an error message. See Errors raised by invalid method calls during SAX-writer states for more information.
END-DOCUMENT( )
If the root tag is not closed and END-DOCUMENT is called, the method fails and generates the following message:
END-DOCUMENT attempted to close the document before the root tag was closed.
You must close the root tag with END-ELEMENT before closing the document
START-ELEMENT( )
WRITE-EMPTY-ELEMENT( )
WRITE-DATA-ELEMENT( )
If FRAGMENT is FALSE, then there may be only one root node, that is, the document-level node. If a call to one of these methods would result in a second document-level node then the following error message is generated:
<method> attempted to create a second document level node in the document.
You must limit each XML document to one document-level node.
END-ELEMENT( )
For each START-ELEMENT method call, you must have a corresponding and matching END-ELEMENT method call. Start and end all nodes to properly form parent and child relationships. All nodes must be started and ended (excluding empty nodes). If END-ELEMENT is called with the incorrect name and prefix, then it fails and generates the message:
END-ELEMENT attempted to close the tag <qname> when the current tag to close was <qname>.
Do not interweave different start and end tags.
WRITE-CHARACTERS( )
Only call WRITE-CHARACTERS from within the document. That is, call it from within the root node. If it is called at the document level, it will fail and generate the following error:
WRITE-CHARACTERS attempted to write character
data at the document level.
INSERT-ATTRIBUTE( )
DECLARE-NAMESPACE( )
Attribute names must be unique. If a call to either of these methods results in a repeated instance of a name, then the methods fail and the following error message will be generated:
<method> attempted to create a second instance of the name <name>.
Also, these methods can only be called when the WRITE-STATUS is SAX-WRITE-TAG or they fail and generate an error message as described in Errors raised by invalid method calls during SAX-writer states. For example:
hSAXWriter:STRICT = TRUE.
hSAXWriter:START-DOCUMENT( ).
hSAXWriter:START-ELEMENT("root","").
hSAXWriter:START-ELEMENT("name","").
hSAXWriter:WRITE-CHARACTER("Fred Smith", 16).
hSAXWriter:END-ELEMENT("root","").
    /*method fails */
hSAXWriter:END-DOCUMENT( ).
This code fragment would generate an error because root was closed before name.