OScript API/Built-in Package Index

Class: DOMParser

The DOMParser Package provides an interface to the Document Object Model (DOM) XML parser. The DOM parser provides the ability to validate an XML document according to a Document Type Definition (DTD), to validate for well-formedness, support for namespaces. A set of methods configure various options for parsing and the ability to retrieve the DOMDocument node that represents the root node of the document.

Class Attributes

If the specified range of text does not fit into a DOMString

Recoverable error.

Error that will stop processing.

If any node is inserted somewhere it doesn't belong

If index or size is negative, or greater than the allowed value

If an attempt is made to add an attribute that is already inuse elsewhere

Introduced in DOM Level 2. If a parameter or an operation is not supported by the underlying object.

If an invalid character is specified, such as in a name

Introduced in DOM Level 2. If an attempt is made to modify the type of the underlying object.

Introduced in DOM Level 2. If an attempt is made to use an object that is not, or no longer, usable

Informational status or message.

Introduced in DOM Level 2. If an attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

If data is specified for a node which does not support data

If an attempt is made to modify an object where modifications are not allowed

If an attempt was made to reference a node in a context where it does not exist

If the implementation does not support the type of object requested

Introduced in DOM Level 2. If an invalid or illegal string is specified.

Exception thrown that does not correspond to any of the known DOM exceptions.

Validation scheme - always validate.

Validation scheme - automatically validate (default).

Validation scheme - never validate.

Warning message.

If a node is used in a different document than the one that created it (that doesn't support it)

Class Methods

New( )

Create a new DOMParser instance.

Instance Methods

Return whether the parser will create comment nodes.

Return whether the parser will create entity reference nodes.

Retrieves the Document node of the parsed document.

Return whether support for XML Namespaces should be enabled.

Return whether the parser will process schema.

Retrieves the error count for the parsed document.

Return whether parsing should exit with the first fatal error.

Return the location for external no namespace schema.

Return the location for external schema.

Return whether the parser should include ignorable whitespace.

Return whether the parser will try and load external DTD.

Return whether the parser will treat a validation constraint error as a fatal error.

Return whether the parser will perform full schema validation.

Return the parser validation scheme.

Parse( String xmlFile )

Parse an XML file into a DOM representation.

ParseBytes( Bytes xmlData )

Parse an XML bytes array into a DOM representation.

SetCreateCommentNodes( Boolean newState )

Determines whether the parser will create comment nodes.

SetCreateEntityReferenceNodes( Boolean newState )

Determines whether the parser will create entity reference nodes.

SetDoNamespaces( Boolean newState )

Determines whether support for XML Namespaces should be enabled.

SetDoSchema( Boolean newState )

Determines whether the parser will process schema.

SetDoValidation( Boolean newState ) Deprecated

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

SetEntityResolver( Dynamic objref, Dynamic entryName )

Sets the object reference and entry point name for the resolve entity reference callback.

SetExitOnFirstFatalError( Boolean newState )

Determines whether parsing should exit with the first fatal error.

SetExpandEntityReferences( Boolean newState ) Deprecated

Determines whether Entities should be expanded when parsed.

Provide the location for external no namespace schema.

SetExternalSchemaLocation( String location )

Provide the location for external schema.

SetIncludeIgnorableWhitespace( Boolean newState )

Determines whether the parser should include ignorable whitespace.

SetLoadExternalDTD( Boolean newState )

Determines whether the parser will try and load external DTD.

SetValidationConstraintFatal( Boolean newState )

Determines whether the parser will treat a validation constraint error as a fatal error.

SetValidationSchemaFullChecking( Boolean newState )

Determines whether the parser will perform full schema validation.

SetValidationScheme( Integer scheme )

Determines the parser validation scheme.

Class Attributes

If the specified range of text does not fit into a DOMString

Integer Error

Recoverable error.

Integer FatalError

Error that will stop processing.

If any node is inserted somewhere it doesn't belong

If index or size is negative, or greater than the allowed value

If an attempt is made to add an attribute that is already inuse elsewhere

Introduced in DOM Level 2. If a parameter or an operation is not supported by the underlying object.

If an invalid character is specified, such as in a name

Introduced in DOM Level 2. If an attempt is made to modify the type of the underlying object.

Introduced in DOM Level 2. If an attempt is made to use an object that is not, or no longer, usable

Integer Message

Informational status or message.

Integer NAMESPACE_ERR

Introduced in DOM Level 2. If an attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

If data is specified for a node which does not support data

If an attempt is made to modify an object where modifications are not allowed

Integer NOT_FOUND_ERR

If an attempt was made to reference a node in a context where it does not exist

If the implementation does not support the type of object requested

Integer SYNTAX_ERR

Introduced in DOM Level 2. If an invalid or illegal string is specified.

Exception thrown that does not correspond to any of the known DOM exceptions.

Integer Val_Always

Validation scheme - always validate. See SetValidationScheme.

Integer Val_Auto

Validation scheme - automatically validate (default). See SetValidationScheme.

Integer Val_Never

Validation scheme - never validate. See SetValidationScheme.

Integer Warning

Warning message.

If a node is used in a different document than the one that created it (that doesn't support it)

Class Methods

New

DOMParser New()

Create a new DOMParser instance.

Returns:

A new DOMParser.

Instance Methods

GetCreateCommentNodes

Boolean GetCreateCommentNodes()

Returns whether the parser will create comment nodes in the DOM tree.

Returns:

Returns TRUE, the parser will create comment nodes in the DOM tree, FALSE otherwise.

GetCreateEntityReferenceNodes

Boolean GetCreateEntityReferenceNodes()

Returns whether the parser will expand/create entity references when parsed.

Returns:

Returns TRUE, if the parser will expand/create entities, FALSE otherwise.

GetDocument

DOMDocument GetDocument()

Retrieves the Document node of the parsed document.

Returns:

The Document node.

GetDoNamespaces

Boolean GetDoNamespaces()

Returns whether parser support for XML Namespaces is enabled.

Returns:

Returns TRUE if parser support for XML Namespaces is enabled, FALSE otherwise.

GetDoSchema

Boolean GetDoSchema()

Returns whether the parser's schema support is enabled.

Returns:

Returns TRUE, if the parser's schema support is enabled, FALSE otherwise.

GetErrorCount

Integer GetErrorCount()

Retrieves the number of parse errors associated with the parsed document.

Returns:

An Integer of the number of errors.

GetExitOnFirstFatalError

Boolean GetExitOnFirstFatalError()

Returns whether parsing should exit with the first fatal error.

Returns:

Returns TRUE if parser should exit parsing when it encounters the the first fatal error, FALSE otherwise.

GetExternalNoNamespaceSchemaLocation

String GetExternalNoNamespaceSchemaLocation()

Returns the previously specified no target namespace XML schema location.

Returns:

Returns a string containing the no target namespace XML schema location that was previously set with SetExternalNoNamespaceSchemaLocation.

GetExternalSchemaLocation

String GetExternalSchemaLocation()

Returns the previously specified list of schemas to use.

Returns:

Returns a string containing the list of schemas to use that was previously set with SetExternalSchemaLocation.

GetIncludeIgnorableWhitespace

Boolean GetIncludeIgnorableWhitespace()

Returns whether parsed text nodes that can be considered ignorable whitespace are included in the DOM tree.

Returns:

Returns TRUE, if the parser will create text nodes for ignorable whitespace, FALSE otherwise.

GetLoadExternalDTD

Boolean GetLoadExternalDTD()

Returns whether the parser will load external DTD when the validation scheme is Val_Never.

Returns:

Returns TRUE, if the loading of external DTD is enabled, FALSE otherwise.

GetValidationConstraintFatal

Boolean GetValidationConstraintFatal()

Returns whether the parser will consider validation constraint errors as fatal.

Returns:

Returns TRUE, if the parser is currently configured to consider validation constraint errors as fatal, FALSE otherwise.

GetValidationSchemaFullChecking

Boolean GetValidationSchemaFullChecking()

Returns whether the parser will perform full schema constraint checking.

Returns:

Returns TRUE, if the parser will perform full schema constraint checking, FALSE otherwise.

GetValidationScheme

Integer GetValidationScheme()

Returns the parser validation scheme.

Returns:

Returns an Integer with one of the defined constant values: Val_Never or Val_Always or Val_Auto.

Parse

Assoc Parse( String xmlFile )

Parse an XML file into a DOM representation.

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.

ParseBytes

Assoc ParseBytes( Bytes xmlData )

Parse an XML bytes array into a DOM representation.

Parameters

xmlData

XML bytes array 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 information like that described in the Parse instance method.

SetCreateCommentNodes

Void SetCreateCommentNodes( Boolean newState )

Determines whether the parser will create comment nodes in the DOM tree.

Parameters

newState

TRUE, enables the creation of comment nodes in the DOM tree.

FALSE, disables the creation of comment nodes in the DOM tree.

Returns:

SetCreateEntityReferenceNodes

Void SetCreateEntityReferenceNodes( Boolean newState )

Determines whether the parser should expand/create entity references.

Parameters

newState

TRUE, if the parser should expand/create entity references, FALSE otherwise.

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 )

Determines whether the parser's schema support is enabled.

Parameters

newState

TRUE, to enable the parser's schema support. FALSE, to disable the parser's schema support.

Returns:

SetDoValidation

Deprecated
Void SetDoValidation( Boolean newState )

Determines whether the XML document should be validated against the Document Type Definition (DTD). This method has been DEPRECATED and is replaced with SetValidationScheme.

Parameters

newState

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

Returns:

SetEntityResolver

Void SetEntityResolver( Dynamic objref,
                        Dynamic entryName )

Sets the object reference and entry point name for the resolve entity callback.

The return value is a string to the resolved entity. An undefined return value indicates to the parser that it should use its default internal entity resolution.

Parameters

objref

The reference to the object that has the script to be used in the callback.

entryName

The script name of the callback that will be executed on callback.

Returns:

SetExitOnFirstFatalError

Void SetExitOnFirstFatalError( Boolean newState )

Determines whether parsing should exit with the first fatal error.

Parameters

newState

TRUE if parsing should exit with the first fatal error.

Returns:

SetExpandEntityReferences

Deprecated
Void SetExpandEntityReferences( Boolean newState )

Determines whether Entities should be expanded when parsed. This method has been DEPRECATED, and is replaced with SetCreateEntityReferenceNodes.

Parameters

newState

TRUE if entities should be expanded when parsed.

Returns:

SetExternalNoNamespaceSchemaLocation

SetExternalNoNamespaceSchemaLocation()

Returns:

SetExternalSchemaLocation

Void SetExternalSchemaLocation( String location )

Provide the no target namespace XML schema location.

Parameters

location

The syntax is the same as for the noNamespaceSchemaLocation attribute in an instance document: e.g, "sample.xsd".

Returns:

SetIncludeIgnorableWhitespace

Void SetIncludeIgnorableWhitespace( Boolean newState )

Determines whether the parser will create text nodes for ignorable whitespace.

Parameters

newState

TRUE, if the parser will create text nodes for ignorable whitespace, FALSE otherwise.

Returns:

SetLoadExternalDTD

Void SetLoadExternalDTD( Boolean newState )

Determines whether the parser will load external DTD when the validation scheme is Val_Never. This flag is ignored if the validation scheme is set (see SetValidationScheme) to Val_Always or Val_Auto.

Parameters

newState

FALSE, parser will ignore any external DTD completely when the validation scheme is Val_Never. TRUE, otherwise (default).

Returns:

SetValidationConstraintFatal

Void SetValidationConstraintFatal( Boolean newState )

Determines whether the parser should consider validation constraint errors as fatal errors.

Parameters

newState

TRUE, if the parser should consider validation constraint errors as fatal errors, FALSE otherwise.

Returns:

SetValidationSchemaFullChecking

Void SetValidationSchemaFullChecking( Boolean newState )

Determines whether the parser will perform checks on the schema grammar itself for additional errors. These additional checks could be time-consuming or memory intensive. The default is FALSE.

Parameters

newState

TRUE, enable full schema constraint checking.

FALSE, disable full schema constraint checking.

Returns:

SetValidationScheme

Void SetValidationScheme( Integer scheme )

Determines parser validation scheme.

Parameters

scheme
  • Val_Never The parser does not report validation errors.
  • Val_Always The parser will always report validation errors.
  • Val_Auto The parser will report validation errors only if a grammar is specified.

Returns:

 Copyright © 2022 OpenText Corporation. All rights reserved.