Class: cXMLDOMParseError

Properties  Events  Methods    Index of Classes

Provides support reporting parsing errors in an XML document



Library: Common (Windows and Web Application) Class Library

Package: Flexml.pkg


When an XML parsing error occurs, the information for that error is obtained by creating a ParseError object and using information from that error object to report the error conditions. When error reporting is complete, the ParseError object is destroyed.

A typical error reporting cycle might be:

The message Get phXMLErrorObject is used to create the error object. It should be sent to the your main XML document object (cXmlDomDocument) and it will return an object handle that points to a newly-created object based on the cXMLDOMParseError class. The error object supports the following read-only properties:

piErrorCode Returns an error code
piFilePos Returns the absolute character position in the file where the error occurred
piLine Returns the number of the line in the document that contains the error
piLinePos Returns the character position of the error within the line in which it occurred
psReason Returns the text description of the source and the reason for the error, and can also include the URL of the DTD or SCHEMA and the node within it that that corresponds to the error
psSrcText Returns the full text of the line that contains the error, or an empty string if the error cannot be assigned to a specific line
psURL Returns the URL of the most recent XML document that contained an error


A simple error handler might look like the following procedure. This creates the error handling object, collects information about the error and directs this information to the DataFlex error handler.

Procedure XMLError
    String sDescr sReason
    Handle hoParseErrorObject
    // 1. Create the error object
    Get phXMLErrorObject of hoXML To hoParseErrorObject
    // 2. Report the error using properties of the parse-error-object
    Get psReason of hoParseErrorObject to sReason
    Move ("Error loading XML file: " * sReason) to sDescr 
    Error DFERR_OPERATOR sDescr

    // 3. Destroy the parse-error-object
    Send Destroy of hoParseErrorObject

This procedure could be used as follows:

Get LoadXMLDocument of hoXML to bOK
If not bOK Begin
   Send XMLError

You can customize your error reporting procedure as needed. As mentioned above, the cXmlDomDocument class supports the method Get phXMLErrorObject, which is used to create an error object. It also supports a method named BasicParseErrorReport, which can be used to generate a standard error response. The code for this method is displayed below. You may find this to be a useful starting point when creating your own error handlers.

Procedure BasicParseErrorReport
    String sProblem sLinePosition sDescr sReason sSource
    Handle hoParseErrorObject

    Get phXMLErrorObject To hoParseErrorObject
    Move ("Cannot load " + (psDocumentName(Self)) + ;
               "."+character(13)+character(10)) To sProblem
    Move ("A Parsing Error has occurred on line " + ;
        string(piLine(hoParseErrorObject)) + " at pos " + ;
                  string(piLinePos(hoParseErrorObject)) + "."+ ;
                  character(13)+character(10) ) To sLinePosition
    Move ("Reason: " + (psReason(hoParseErrorObject))) To sReason
    Move ("Source: " + (psSrcText(hoParseErrorObject))) To sSource
    Move (sProblem + sLinePosition + sReason + sSource) To sDescr
    Error DFERR_OPERATOR sDescr
    Send Destroy of hoParseErrorObject

If you use this error handler, remember that you must send the BasicParseErrorReport to the XML object (which is where it is defined).

Get LoadXMLDocument of hoXML to bOK
If not bOK Begin
   // this will print out a basic error report
   Send BasicParseErrorReport of hoXml

Using the XML Classes

The cXmlDomDocument class is the starting point for most XML processing. Refer to the cXmlDomDocument class for more information about the XML Document Object Model (DOM) and using XML within DataFlex. Samples are provided in this section.