libSBML C API  5.18.0
XMLError_t Class Reference

Detailed Description

XML-level errors, warnings and other diagnostics.

This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.

LibSBML can be configured to use any of a number of XML parsers; at the time of this writing, libSBML supports Xerces versions 2.4 through 3.1, Expat version 1.95.x and higher, and libxml2 version 2.6.16 and higher. These parsers each report different status codes for the various exceptions that can occur during XML processing. The XMLError_t object class abstracts away from the particular diagnostics reported by the different parsers and presents a single uniform interface and set of status codes, along with operations for manipulating the error objects.

When the libSBML XML parser layer encounters an error in the XML content being processed, or when there is something else wrong (such as an out-of-memory condition), the problems are reported as XMLError_t objects. Each XMLError_t object instance has an identification number that identifies the nature of the problem. This error identifier will be up to five digits long and drawn from the enumeration XMLErrorCode_t. Applications can use the error identifiers as a means of recognizing the error encountered and changing their behavior if desired.

Integer error codes are useful for software, but not so much for telling humans what happened. For this reason, XMLError_t also provides two text messages describing the nature of the error. These messages are accessible by means of the methods XMLError_t::getShortMessage() and XMLError_t::getMessage(). The method XMLError_t::getShortMessage() returns a very brief synopsis of the warning or error condition, whereas XMLError_t::getMessage() returns a longer explanation. These text strings are suitable for displaying to human users.

Each XMLError_t object also contains a category code; its value may be retrieved using the method XMLError_t::getCategory(). Category values are drawn from the enumeration XMLErrorCategory_t described below. Categories are used by libSBML to provide more information to calling programs about the nature of a given error.

In addition to category codes, each XMLError_t object also has a severity code; its value may be retrieved using the method XMLError_t::getSeverity(). Severity code values are drawn from the enumeration XMLErrorSeverity_t, described below. Severity levels range from informational (LIBSBML_SEV_INFO) to fatal errors (LIBSBML_SEV_FATAL).

Finally, XMLError_t objects record the line and column near where the problem occurred in the XML content. The values can be retrieved using the methods XMLError_t::getLine() and XMLError_t::getColumn(). We say "near where the problem occurred", because many factors affect how accurate the line/column information ultimately is. For example, sometimes, the underlying XML parsers can only report such information for the parent XML element where an error occurs, and not for the specific point where the problem occurs. In other situations, some parsers report invalid line and/or column numbers altogether. If this occurs, libSBML sets the line and/or column number in the XMLError_t object to either 0 or the value of the maximum unsigned long integer representable on the platform where libSBML is running. The probability that a true line or column number in an SBML model would equal this value is vanishingly small; thus, if an application encounters these values in an XMLError_t object, it can assume no valid line/column number could be provided by libSBML in that situation.

XMLErrorCode_t

This is an enumeration of all the error and warning codes returned by the XML layer in libSBML. Each code is an integer with a 4-digit value less than 10000. The following table lists each possible value and a brief description of its meaning.

Possible XMLError_t error codes. Depending on the programming language in use, the Enumerator values will be defined either as a value from an enumeration type (XMLErrorCode_t) or as integer constants. To make this table more compact, we have shortened the identifiers for the category and severity codes to their essential parts. To get the actual names of the constants, prepend LIBSBML_CAT_ to the category names and LIBSBML_SEV_ to the severity names shown in the two right-hand columns.
Enumerator Meaning Category Severity
XMLUnknownErrorUnrecognized error encountered internallyINTERNALFATAL
XMLOutOfMemory Out of memorySYSTEMFATAL
XMLFileUnreadable File unreadableSYSTEMERROR
XMLFileUnwritable File unwritableSYSTEMERROR
XMLFileOperationErrorError encountered while attempting file operationSYSTEMERROR
XMLNetworkAccessErrorNetwork access errorSYSTEMERROR
InternalXMLParserErrorInternal XML parser state errorINTERNALFATAL
UnrecognizedXMLParserCodeXML parser returned an unrecognized error codeINTERNALFATAL
XMLTranscoderErrorCharacter transcoder errorINTERNALFATAL
MissingXMLDeclMissing XML declaration at beginning of XML inputXMLERROR
MissingXMLEncodingMissing encoding attribute in XML declarationXMLERROR
BadXMLDeclInvalid or unrecognized XML declaration or XML encodingXMLERROR
BadXMLDOCTYPEInvalid, malformed or unrecognized XML DOCTYPE declarationXMLERROR
InvalidCharInXMLInvalid character in XML contentXMLERROR
BadlyFormedXMLXML content is not well-formedXMLERROR
UnclosedXMLTokenUnclosed XML tokenXMLERROR
InvalidXMLConstructXML construct is invalid or not permittedXMLERROR
XMLTagMismatchElement tag mismatch or missing tagXMLERROR
DuplicateXMLAttributeDuplicate XML attributeXMLERROR
UndefinedXMLEntityUndefined XML entityXMLERROR
BadProcessingInstructionInvalid, malformed or unrecognized XML processing instructionXMLERROR
BadXMLPrefixInvalid or undefined XML namespace prefixXMLERROR
BadXMLPrefixValueInvalid XML namespace prefix valueXMLERROR
MissingXMLRequiredAttributeMissing a required XML attributeXMLERROR
XMLAttributeTypeMismatchData type mismatch for the value of an attributeXMLERROR
XMLBadUTF8ContentInvalid UTF8 contentXMLERROR
MissingXMLAttributeValueMissing or improperly formed attribute valueXMLERROR
BadXMLAttributeValueInvalid or unrecognizable attribute valueXMLERROR
BadXMLAttributeInvalid, unrecognized or malformed attributeXMLERROR
UnrecognizedXMLElementElement either not recognized or not permittedXMLERROR
BadXMLCommentBadly formed XML commentXMLERROR
BadXMLDeclLocationXML declaration not permitted in this locationXMLERROR
XMLUnexpectedEOFReached end of input unexpectedlyXMLERROR
BadXMLIDValueValue is invalid for XML ID, or has already been usedXMLERROR
BadXMLIDRefXML ID value was never declaredXMLERROR
UninterpretableXMLContentUnable to interpret contentXMLERROR
BadXMLDocumentStructureBad XML document structureXMLERROR
InvalidAfterXMLContentEncountered invalid content after expected contentXMLERROR
XMLExpectedQuotedStringExpected to find a quoted stringXMLERROR
XMLEmptyValueNotPermittedAn empty value is not permitted in this contextXMLERROR
XMLBadNumberInvalid or unrecognized numberXMLERROR
XMLBadColonColon characters are invalid in this contextXMLERROR
MissingXMLElementsOne or more expected elements are missingXMLERROR
XMLContentEmptyMain XML content is emptyXMLERROR

XMLErrorCategory_t

As discussed above, each XMLError_t object contains a value for a category identifier, describing the type of issue that the XMLError_t object represents. The category can be retrieved from an XMLError_t object using the method XMLError_t::getCategory(). The value is chosen from the enumeration of category codes XMLErrorCategory_t. The following table lists each possible value and a brief description of its meaning.

Enumerator Meaning
LIBSBML_CAT_INTERNAL A problem involving the libSBML software itself or the underlying XML parser. This almost certainly indicates a software defect (i.e., bug) in libSBML. Please report instances of this to the libSBML developers.
LIBSBML_CAT_SYSTEM A problem reported by the operating system, such as an inability to read or write a file. This indicates something that is not a program error but is outside of the control of libSBML.
LIBSBML_CAT_XML A problem in the XML content itself. This usually arises from malformed XML or the use of constructs not permitted in SBML.

XMLErrorSeverity_t

As described above, each XMLError_t object contains a value for a severity code, describing how critical is the issue that the XMLError_t object represents. The severity can be retrieved from an XMLError_t object using the method XMLError_t::getSeverity(). The value is chosen from the enumeration of category codes XMLErrorSeverity_t. The following table lists each possible value and a brief description of its meaning.

Enumerator Meaning
LIBSBML_SEV_INFO The error is actually informational and not necessarily a serious problem.
LIBSBML_SEV_WARNING The error object represents a problem that is not serious enough to necessarily stop the problem, but applications should take note of the problem and evaluate what its implications may be.
LIBSBML_SEV_ERROR The error object represents a serious error. The application may continue running but it is unlikely to be able to continue processing the same XML file or data stream.
LIBSBML_SEV_FATAL A serious error occurred, such as an out-of-memory condition, and the software should terminate immediately.
Examples:
createExampleSBML.c.

Public Member Functions

LIBLAX_EXTERN XMLError_tXMLError_create (void)
 Creates a new XMLError_t to report that something occurred. More...
 
LIBLAX_EXTERN XMLError_tXMLError_createWithIdAndMessage (unsigned int errorId, const char *message)
 Creates a new XMLError_t with the identification number and detailed message set. More...
 
LIBLAX_EXTERN void XMLError_free (XMLError_t *error)
 Frees the given XMLError_t structure. More...
 
LIBLAX_EXTERN unsigned int XMLError_getCategory (const XMLError_t *error)
 Return the category of this XMLError_t. More...
 
LIBLAX_EXTERN const char * XMLError_getCategoryAsString (const XMLError_t *error)
 Return the category of this XMLError_t as a string. More...
 
LIBLAX_EXTERN unsigned int XMLError_getColumn (const XMLError_t *error)
 Return the column number where this XMLError_t occurred. More...
 
LIBLAX_EXTERN unsigned int XMLError_getErrorId (const XMLError_t *error)
 Returns the id of this XMLError_t. More...
 
LIBLAX_EXTERN unsigned int XMLError_getLine (const XMLError_t *error)
 Return the line number where this XMLError_t occurred. More...
 
LIBLAX_EXTERN const char * XMLError_getMessage (const XMLError_t *error)
 Returns the message text of this XMLError_t. More...
 
LIBLAX_EXTERN unsigned int XMLError_getSeverity (const XMLError_t *error)
 Return the severity of this XMLError_t. More...
 
LIBLAX_EXTERN const char * XMLError_getSeverityAsString (const XMLError_t *error)
 Return the severity of this XMLError_t as a string. More...
 
LIBLAX_EXTERN const char * XMLError_getShortMessage (const XMLError_t *error)
 Returns the short message text of this XMLError_t. More...
 
LIBLAX_EXTERN int XMLError_isError (const XMLError_t *error)
 Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is an error. More...
 
LIBLAX_EXTERN int XMLError_isFatal (const XMLError_t *error)
 Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is a fatal error. More...
 
LIBLAX_EXTERN int XMLError_isInfo (const XMLError_t *error)
 Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is for information only. More...
 
LIBLAX_EXTERN int XMLError_isWarning (const XMLError_t *error)
 Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is a warning. More...
 
LIBLAX_EXTERN void XMLError_print (const XMLError_t *error, FILE *stream)
 Outputs this XMLError_t to stream in the following format (and followed by a newline): More...
 

Member Function Documentation

LIBLAX_EXTERN XMLError_t * XMLError_create ( void  )

Creates a new XMLError_t to report that something occurred.

LIBLAX_EXTERN XMLError_t * XMLError_createWithIdAndMessage ( unsigned int  errorId,
const char *  message 
)

Creates a new XMLError_t with the identification number and detailed message set.

If the identifier is < 10000, it must be one of the predefined XML layer error codes.

Parameters
errorIdan unsigned int, the identification number of the error.
messagea string, the error message.
LIBLAX_EXTERN void XMLError_free ( XMLError_t error)

Frees the given XMLError_t structure.

Parameters
errorthe XMLError_t structure to be freed.
LIBLAX_EXTERN unsigned int XMLError_getCategory ( const XMLError_t error)

Return the category of this XMLError_t.

The possible values (for the XML layers) are those from the enumeration XMLErrorCategory_t.

Parameters
errorthe XMLError_t from which to return the category.
Returns
the category of this XMLError_t.
LIBLAX_EXTERN const char * XMLError_getCategoryAsString ( const XMLError_t error)

Return the category of this XMLError_t as a string.

Parameters
errorthe XMLError_t from which to return the category.
Returns
string representing the category of this XMLError_t.
LIBLAX_EXTERN unsigned int XMLError_getColumn ( const XMLError_t error)

Return the column number where this XMLError_t occurred.

Parameters
errorthe XMLError_t from which to return the column number.
Returns
the column number where this XMLError_t occurred.
LIBLAX_EXTERN unsigned int XMLError_getErrorId ( const XMLError_t error)

Returns the id of this XMLError_t.

Parameters
errorthe XMLError_t from which to return the id.
Returns
the id of this XMLError_t.
LIBLAX_EXTERN unsigned int XMLError_getLine ( const XMLError_t error)

Return the line number where this XMLError_t occurred.

Parameters
errorthe XMLError_t from which to return the line number.
Returns
the line number where this XMLError_t occurred.
LIBLAX_EXTERN const char * XMLError_getMessage ( const XMLError_t error)

Returns the message text of this XMLError_t.

Parameters
errorthe XMLError_t from which to return the message.
Returns
the message text of this XMLError_t.
LIBLAX_EXTERN unsigned int XMLError_getSeverity ( const XMLError_t error)

Return the severity of this XMLError_t.

The possible values (for the XML layer) are those from the enumeration XMLErrorSeverity_t.

Parameters
errorthe XMLError_t from which to return the severity.
Returns
the severity of this XMLError_t.
LIBLAX_EXTERN const char * XMLError_getSeverityAsString ( const XMLError_t error)

Return the severity of this XMLError_t as a string.

Parameters
errorthe XMLError_t from which to return the severity.
Returns
string representing the severity of this XMLError_t.
LIBLAX_EXTERN const char * XMLError_getShortMessage ( const XMLError_t error)

Returns the short message text of this XMLError_t.

Parameters
errorthe XMLError_t from which to return the short message.
Returns
the message text of this XMLError_t.
LIBLAX_EXTERN int XMLError_isError ( const XMLError_t error)

Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is an error.

Parameters
errorthe XMLError_t.
Returns
1 (true) if this XMLError_t is an error, 0 (false) otherwise.
Examples:
createExampleSBML.c.
LIBLAX_EXTERN int XMLError_isFatal ( const XMLError_t error)

Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is a fatal error.

Parameters
errorthe XMLError_t.
Returns
1 (true) if this XMLError_t is a fatal error, 0 (false) otherwise.
Examples:
createExampleSBML.c.
LIBLAX_EXTERN int XMLError_isInfo ( const XMLError_t error)

Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is for information only.

Parameters
errorthe XMLError_t.
Returns
1 (true) if this XMLError_t is for informational purposes only, 0 (false) otherwise.
LIBLAX_EXTERN int XMLError_isWarning ( const XMLError_t error)

Predicate returning 1 (true) or 0 (false) depending on whether this XMLError_t structure is a warning.

Parameters
errorthe XMLError_t.
Returns
1 (true) if this XMLError_t is a warning, 0 (false) otherwise.
LIBLAX_EXTERN void XMLError_print ( const XMLError_t error,
FILE *  stream 
)

Outputs this XMLError_t to stream in the following format (and followed by a newline):

line: (id) message

Parameters
errorthe XMLError_t structure to write.
streamthe stream to write to.