OScript API/Built-in Package Index

Class: SAXParser

The SAXParser Package provides an interface to the XML SAX parser. The SAX parser provides the ability to use a lightweight XML parser. One set of methods configures the various options for parsing. Another set of methods is used to set up the callbacks that are necessary for the SAX parser to report its results. Two callbacks, StartDocument and EndDocument, signals of the start and end of parsing a document. Another set of callbacks, StartElement and EndElement tell when the start and end of a tag is found. Last the callback, Characters, reports the data value for a tag.

Class Attributes

Text is too large for a DOMString.

Error.

FatalError.

Attempt to insert a node where it doesn't belong.

Index is out of bounds.

Parameter or operation is not supported by the object.

An invalid character was specified.

An attempt to modify the type of the object.

The object is no longer usable.

Message.

Modification of object violates the namespace.

This node does not support data.

Modifications are not allowed.

Reference to a node in a context where it does not exist.

The implementation does not support this type of object.

An invalid or illegal string has been specified.

Unknown exception.

The parser will always report validation errors.

The parser will report validation errors only if a grammar is specified.

Do not report validation errors.

Warning.

Attempt to use a node in a different document.

Class Methods

New( )

Create a new SAXParser instance.

Instance Methods

Parse( String xmlFile )

Parse an XML file.

ParseFirst( String xmlFile )

Start a progressive parse on a XML file.

ParseFirstString( String xmlString )

Start a progressive parse on a string containing a XML document.

This method is used to continue with progressive parsing of XML files started by a call to 'parseFirst' method.

Reset the parser after a progressive parse.

ParseString( String xmlDoc )

Parse a XML doc contained in a string.

Forces the removal of all temporary files if a document is not being parsed.

SetCharactersHandler( Dynamic sax, Dynamic handler )

Receive notification of character data.

SetDeleteTmpFiles( Boolean newState )

Determines if temporary files should be deleted immediately after the element that uses the the temporary file is processed.

SetDocumentLocatorHandler( Dynamic sax, Dynamic handler )

Receive an object for locating the origin of SAX document events.

SetDoNamespaces( Boolean newState )

Determines whether support for XML Namespaces should be enabled.

SetDoSchema( Boolean newState )

Set the 'do schema' flag.

SetDoValidation( Boolean newState )

Determines whether the XML document should be validated against the Document Type Definition (DTD).

SetEndDocumentHandler( Dynamic sax, Dynamic handler )

Receive notification of the end of a document.

SetEndElementHandler( Dynamic sax, Dynamic handler )

Receive notification of the end of an element.

SetEndPrefixMappingHandler( Dynamic sax, Dynamic handler )

Receive notification of the end of a namespace prefix mapping.

SetEntityResolver( Dynamic sax, Dynamic resolver )

Set an entity resolver callback.

SetExitOnFirstFatalError( Boolean newState )

Determines whether parsing should be ended when the first fatal error occurs.

SetIgnorableWhitespaceHandler( Dynamic sax, Dynamic handler )

Receive notification of ignorable whitespace in element content.

SetProcessingInstructionHandler( Dynamic sax, Dynamic handler )

Receive notification of a processing instruction.

SetResetDocumentHandler( Dynamic sax, Dynamic handler )

Reset the Document object on its reuse.

SetSkippedEntityHandler( Dynamic sax, Dynamic handler )

Receive notification for each entity skipped.

SetStartDocumentHandler( Dynamic sax, Dynamic handler )

Receive notification of the beginning of a document.

SetStartElementHandler( Dynamic sax, Dynamic handler )

Receive notification of the beginning of an element.

SetStartPrefixMappingHandler( Dynamic sax, Dynamic handler )

Receive notification of the beginning of a namespace prefix mapping.

SetTmpFileTags( List tags )

Sets a list of tags that require temporary files because their content (value) is too large for an Oscript string.

SetValidationConstraintFatal( Boolean newState )

This method allows users to set the parser's behaviour when it encounters a validtion constraint error.

SetValidationSchemaFullChecking( Boolean schemaFullChecking )

This method allows the user to turn full Schema constraint checking on/off.

SetValidationScheme( Integer newScheme )

This method allows users to set the validation scheme to be used by this parser.

Class Attributes

Text is too large for a DOMString.

Integer Error

Error.

Integer FatalError

FatalError.

Attempt to insert a node where it doesn't belong.

Index is out of bounds.

Parameter or operation is not supported by the object.

An invalid character was specified.

An attempt to modify the type of the object.

The object is no longer usable.

Integer Message

Message

Modification of object violates the namespace.

This node does not support data.

Modifications are not allowed.

Reference to a node in a context where it does not exist.

The implementation does not support this type of object.

Error SYNTAX_ERR

An invalid or illegal string has been specified.

Unknown exception.

The parser will always report validation errors.

Integer ValidateAuto

The parser will report validation errors only if a grammar is specified.

Integer ValidateNever

Do not report validation errors.

Integer Warning

Warning.

Attempt to use a node in a different document.

Class Methods

New

SAXParser New()

Create a new SAXParser instance.

Returns:

A new SAXParser.

Instance Methods

Parse

Assoc Parse( String xmlFile )

Parse an XML file.

Parameters

xmlFile

XML file to be parsed.

Returns:

An Assoc that contains:
Boolean OK Status of the parse.
RecArray Error Errors that occurred during parsing.

If the status of the parse is false, then the error RecArray contains:

String ErrType The type of error: warning, error or fatal.
String ErrMsg Parser generated error message.
String PublicID Public Identifier of the XML file, filename in this instance.
String SystemId System Identifier of the XML file, usually empty.
Integer LineNumber Line number in the file in which the error occurred.
Integer ColumnNumber Column number in the file in which the error occurred.

ParseFirst

Boolean ParseFirst( String xmlFile )

This method is used to start a progressive parse on a XML file. To continue parsing, subsequent calls must be to the parseNext method.

Parameters

xmlFile

Path to the XML file to be parsed.

Returns:

ParseFirstString

Boolean ParseFirstString( String xmlString )

This method is used to start a progressive parse on a string containing a XML document. To continue parsing, subsequent calls must be to the parseNext method.

Parameters

xmlString

String containing the XML document to be parsed.

Returns:

ParseNext

Boolean ParseNext()

This method is used to continue with progressive parsing of XML files started by a call to 'parseFirst' method.

Returns:

ParseReset

Void ParseReset()

Reset the parser after a progressive parse.

Returns:

ParseString

Assoc ParseString( String xmlDoc )

Parse a XML doc contained in a string.

Parameters

xmlDoc

The string containing the SML doc.

Returns:

RemoveTmpFiles

Void RemoveTmpFiles()

Removes temporary files if a document is not being parsed.

Returns:

SetCharactersHandler

Void SetCharactersHandler( Dynamic sax,
                           Dynamic handler )

Receive notification of character data. The characters handler is void Characters ( String name, Integer size ) , where the tag name is stored in the variable name, and the variable size is the length of the name.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetDeleteTmpFiles

Void SetDeleteTmpFiles( Boolean newState )

Determines if temporary files should be deleted immediately after the element that uses the the temporary file is processed.

Parameters

newState

True if temporary file should be deleted after tag is processed.

Returns:

SetDocumentLocatorHandler

Void SetDocumentLocatorHandler( Dynamic sax,
                                Dynamic handler )

Receive an object for locating the origin of SAX document events.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetDoNamespaces

Void SetDoNamespaces( Boolean newState )

Determines whether support for XML Namespaces should be enabled.

Parameters

newState

True if namespaces should be enabled.

Returns:

SetDoSchema

Void SetDoSchema( Boolean newState )

Set the 'do schema' flag. This method allows users to enable or disable the parser's schema processing. When set to false, parser will not process any schema found.

Parameters

newState

The value specifying whether schema support should be enforced or not.

Returns:

SetDoValidation

Void SetDoValidation( Boolean newState )

Determines whether the XML document should be validated against the Document Type Definition (DTD).

Parameters

newState

True if the XML document should be validated against the DTD.

Returns:

SetEndDocumentHandler

Void SetEndDocumentHandler( Dynamic sax,
                            Dynamic handler )

Receive notification of the end of a document. The end document handler is EndDocument ().

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetEndElementHandler

Void SetEndElementHandler( Dynamic sax,
                           Dynamic handler )

Receive notification of the end of an element. The end element handler is void EndElement ( String name ) , where the tag name is stored in the variable name.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetEndPrefixMappingHandler

Void SetEndPrefixMappingHandler( Dynamic sax,
                                 Dynamic handler )

Receive notification of the end of a namespace prefix mapping.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetEntityResolver

Void SetEntityResolver( Dynamic sax,
                        Dynamic resolver )

Set an entity resolver callback.

Parameters

sax

An instance of the sax parser.

resolver

An instance of the resolver callback method.

Returns:

SetExitOnFirstFatalError

Void SetExitOnFirstFatalError( Boolean newState )

Determines whether parsing should be ended when the first fatal error occurs.

Parameters

newState

True if exit on first error.

Returns:

SetIgnorableWhitespaceHandler

Void SetIgnorableWhitespaceHandler( Dynamic sax,
                                    Dynamic handler )

Receive notification of the end of an element. The ignorable whitespace handler is void IgnorableWhitespace ( String chars, Integer size ) , where the variable chars stores the characters to ignore, and the variable size is the length of the chars.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetProcessingInstructionHandler

Void SetProcessingInstructionHandler( Dynamic sax,
                                      Dynamic handler )

Receive notification of a processing instruction. The handler for processing instruction of the form void ProcessingInstruction ( String target, String data ) , where target is the target of the processing instruction and data is the processing instruction data.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetResetDocumentHandler

Void SetResetDocumentHandler( Dynamic sax,
                              Dynamic handler )

Reset the document on its reuse. The handler is void ResetDocument ( )

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetSkippedEntityHandler

Void SetSkippedEntityHandler( Dynamic sax,
                              Dynamic handler )

Receive notification for each entity skipped

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetStartDocumentHandler

Void SetStartDocumentHandler( Dynamic sax,
                              Dynamic handler )

Receive notification of the beginning of a document. The handler signature is StartDocument ( ).

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetStartElementHandler

Void SetStartElementHandler( Dynamic sax,
                             Dynamic handler )

Receive notification of the beginning of an element. The handler signature is StartElement ( String name, Assoc attributes ), where the name of the element is the first argument and attributes is an Assoc which holds the name, value pairs for the attributes of the element.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetStartPrefixMappingHandler

Void SetStartPrefixMappingHandler( Dynamic sax,
                                   Dynamic handler )

Receive notification of the beginning of a namespace prefix mapping.

Parameters

sax

An instance of the sax parser.

handler

An instance of the handler method.

Returns:

SetTmpFileTags

Void SetTmpFileTags( List tags )

Sets a list of tags that require temporary files because their content (value) is too large for an oscript string. If a tag is passed in this list, then when the StartElement callback occurs an attribute "filename" is added to the attribute list. The value for the attribute holds the name of the temporary file.

Parameters

tags

List of strings that will require temporary files.

Returns:

SetValidationConstraintFatal

Void SetValidationConstraintFatal( Boolean newState )

This method allows users to set the parser's behaviour when it encounters a validtion constraint error. If set to true, and the the parser will treat validation error as fatal and will exit depends on the state of "getExitOnFirstFatalError". If false, then it will report the error and continue processing.

Parameters

newState

If true, the parser will exit if "setExitOnFirstFatalError" is set to true.

Returns:

SetValidationSchemaFullChecking

Void SetValidationSchemaFullChecking( Boolean schemaFullChecking )

This method allows the user to turn full Schema constraint checking on/off. Only takes effect if Schema validation is enabled. If turned off, partial constraint checking is done.

Parameters

schemaFullChecking

True to turn on full schema constraint checking.

Returns:

SetValidationScheme

Void SetValidationScheme( Integer newScheme )

This method allows users to set the validation scheme to be used by this parser. The value of newScheme is one of the ValSchemes enumerated values defined by this class:

Parameters

newScheme

The new validation scheme to use.

Returns:

 Copyright © 2022 OpenText Corporation. All rights reserved.