Options
All
  • Public
  • Public/Protected
  • All
Menu

A document validator.

Hierarchy

  • Validator
    • Validator

Index

Constructors

constructor

  • Parameters

    • schema: Grammar

      A path to the schema to pass to salve for validation. This is a path that will be interpreted by RequireJS. The schema must have already been prepared for use by salve. See salve's documentation. Or this can be a Grammar object that has already been produced from salve's constructTree.

    • root: Element | Document

      The root of the DOM tree to validate. This root contains the document to validate but is not part of it.

    • modeValidators: ModeValidator[]

      The mode-specific validators to use.

    Returns Validator

Properties

errors

errors: ErrorData[]

The current set of errors.

events

events: Consuming<Events>

Private modeValidators

modeValidators: ModeValidator[]

The mode-specific validators to use.

Methods

Protected _processError

  • _processError(error: ErrorData): void
  • This method should be called whenever a new error is detected. It records the error and emits the corresponding event.

    emits

    module:validator~Validator#error

    Parameters

    • error: ErrorData

      The error found.

    Returns void

_runDocumentValidation

  • _runDocumentValidation(): void
  • Runs document-wide validation specific to the mode passed to the validator.

    Returns void

getDocumentNamespaces

  • getDocumentNamespaces(): object
  • Get the namespaces used in the document. This method does not cache its information and scan the whole document independently of the current validation status.

    Returns object

    An object whose keys are namespace prefixes and values are lists of namespace URIs. The values are lists because prefixes can be redefined in a document.

    • [key: string]: string[]

getErrorsFor

  • getErrorsFor(node: Node): ErrorData[]
  • Obtain the validation errors that belong to a specific node.

    The term "that belong to" has a specific meaning here:

    • An error in the contents of an element belongs to the element whose contents are incorrect. For instance if in the sequence <foo><blip/></foo> the tag <blip/> is out of place, then the error belongs to the node for the element foo, not the node for the element blip.

    • Attribute errors belong to the element node to which the attributes belong.

    Parameters

    • node: Node

      The node whose errors we want to get.

    Returns ErrorData[]

    The errors.

getNodeProperty

  • getNodeProperty<T>(node: Node, key: T): CustomNodeProperties[T] | undefined
  • Function allowing to get a custom properties set on Node objects by this class.

    Type parameters

    • T: CustomNodeProperty

    Parameters

    • node: Node
    • key: T

    Returns CustomNodeProperties[T] | undefined

getSchemaNamespaces

  • getSchemaNamespaces(): string[]
  • Get the namespaces defined in the schema passed to the Validator.

    Returns string[]

    The namespaces known to the schema.

getWorkingState

  • getWorkingState(): WorkingStateData
  • Gets the validator working state.

    Returns WorkingStateData

    The working state

possibleAt

  • possibleAt(loc: dloc.DLoc, attributes?: undefined | true | false): EventSet
  • possibleAt(container: Node, index: number, attributes?: undefined | true | false): EventSet
  • Returns the set of possible events for the location specified by the parameters.

    Parameters

    • loc: dloc.DLoc

      Location at which to get possibilities.

    • Optional attributes: undefined | true | false

      Whether we are interested in the attribute events of the node pointed to by container, index. If true the node pointed to by container, index must be an element, and the returned set will contain attribute events.

    Returns EventSet

    A set of possible events.

  • Parameters

    • container: Node
    • index: number
    • Optional attributes: undefined | true | false

    Returns EventSet

possibleWhere

  • possibleWhere(container: Node, event: Event): number[]
  • Finds the locations in a node where a certain validation event is possible.

    Parameters

    • container: Node

      A node.

    • event: Event

      The event to search for. The event should contain the same data as would be passed to fireEvent. Specifically, name patterns may not be used in the event passed to this method.

    Returns number[]

    The locations in container where the event is possible.

resetTo

  • resetTo(node: Node): void
  • Reset validation to continue from a certain point.

    Parameters

    • node: Node

      The element to start validation from.

    Returns void

resolveNameAt

  • resolveNameAt(container: Node, index: number, name: string, attribute?: undefined | true | false): EName | undefined
  • Resolve a qualified name to an expanded name. See "salve".NameResolver.resolveName for what resolving means. This method takes into account namespaces defined on parent nodes.

    Parameters

    • container: Node

      Where to perform the operation.

    • index: number

      Where to perform the operation.

    • name: string

      The name to rresolve.

    • Optional attribute: undefined | true | false

    Returns EName | undefined

    The resolved name.

restartAt

  • restartAt(node: Node): void
  • Restarts validation from a specific point. After the call returns, the background validation will be in effect. (So calling it on a stopped validator has the side effect of starting it.)

    Parameters

    • node: Node

      The element to start validation from.

    Returns void

speculativelyValidate

  • speculativelyValidate(loc: dloc.DLoc, toParse: Node | Node[]): ErrorData[] | false
  • speculativelyValidate(container: Node, index: number, toParse: Node | Node[]): ErrorData[] | false
  • Validate a DOM fragment as if it were present at the point specified in the parameters in the DOM tree being validated.

    WARNING: This method will not catch unclosed elements. This is because the fragment is not considered to be a "complete" document. Unclosed elements or fragments that are not well-formed must be caught by other means.

    Parameters

    • loc: dloc.DLoc

      The location in the tree to start at.

    • toParse: Node | Node[]

      The fragment to parse.

    Returns ErrorData[] | false

    An array of errors if there is an error. Otherwise returns false.

  • Parameters

    • container: Node
    • index: number
    • toParse: Node | Node[]

    Returns ErrorData[] | false

speculativelyValidateFragment

  • speculativelyValidateFragment(loc: dloc.DLoc, toParse: Element): ErrorData[] | false
  • speculativelyValidateFragment(container: Node, index: number, toParse: Element): ErrorData[] | false
  • Validate a DOM fragment as if it were present at the point specified in the parameters in the DOM tree being validated.

    WARNING: This method will not catch unclosed elements. This is because the fragment is not considered to be a "complete" document. Unclosed elements or fragments that are not well-formed must be caught by other means.

    Parameters

    • loc: dloc.DLoc

      The location in the tree to start at.

    • toParse: Element

      The fragment to parse. This fragment must not be part of the tree that the validator normally validates. (It can be cloned from that tree.) This fragment must contain a single top level element which has only one child. This child is the element that will actually be parsed.

    Returns ErrorData[] | false

    An array of errors if there is an error. Otherwise returns false.

  • Parameters

    • container: Node
    • index: number
    • toParse: Element

    Returns ErrorData[] | false

start

  • start(): void
  • Starts the background validation process.

    Returns void

stop

  • stop(): void
  • Stops background validation.

    Returns void

unresolveNameAt

  • unresolveNameAt(container: Node, index: number, uri: string, name: string): string | undefined
  • Unresolve an expanded name to a qualified name. See "salve".NameResolver.unresolveName for what unresolving means. This method takes into account namespaces defined on parent nodes.

    Parameters

    • container: Node

      Where to perform the operation.

    • index: number

      Where to perform the operation.

    • uri: string

      The URI to unresolve.

    • name: string

      The name to unresolve.

    Returns string | undefined

    The unresolved name.

Generated using TypeDoc