ELP Parser API

SchemaValidator
in package

Validate project XML against a caller-supplied trusted XSD or DTD.

Table of Contents

Constants

TYPE_DTD  : mixed = 'dtd'
TYPE_XSD  : mixed = 'xsd'

Methods

validate()  : array{valid: bool, errors: array>}
Validate XML against a trusted local schema.
collectErrors()  : array<int, array<string, mixed>>
Convert libxml errors to stable arrays.
failure()  : array{valid: bool, errors: array>}
Build a single stable validation failure.
insertDoctype()  : string
Insert a trusted DOCTYPE after the XML declaration when present.
localFileUri()  : string
Convert an absolute local path to a file URI.
validateDtd()  : array{valid: bool, errors: array>}
Validate XML against DTD.
validateXsd()  : array{valid: bool, errors: array>}
Validate XML against XSD.

Constants

Methods

validate()

Validate XML against a trusted local schema.

public validate(string $xmlContent, string $schemaPath[, string $type = self::TYPE_XSD ]) : array{valid: bool, errors: array>}
Parameters
$xmlContent : string

XML content.

$schemaPath : string

Trusted local XSD or DTD path.

$type : string = self::TYPE_XSD

Schema type.

Return values
array{valid: bool, errors: array>}

collectErrors()

Convert libxml errors to stable arrays.

private collectErrors() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

failure()

Build a single stable validation failure.

private failure(string $code, string $message) : array{valid: bool, errors: array>}
Parameters
$code : string

Error code.

$message : string

Error message.

Return values
array{valid: bool, errors: array>}

insertDoctype()

Insert a trusted DOCTYPE after the XML declaration when present.

private insertDoctype(string $xml, string $doctype) : string
Parameters
$xml : string

XML content without a DOCTYPE.

$doctype : string

Trusted DOCTYPE declaration.

Return values
string

localFileUri()

Convert an absolute local path to a file URI.

private localFileUri(string $path) : string
Parameters
$path : string

Absolute local path.

Return values
string

validateDtd()

Validate XML against DTD.

private validateDtd(string $xmlContent, string $schemaPath) : array{valid: bool, errors: array>}

The package-supplied DOCTYPE is removed and replaced with the trusted local DTD path supplied by the caller.

Parameters
$xmlContent : string

XML content.

$schemaPath : string

Trusted DTD path.

Return values
array{valid: bool, errors: array>}

validateXsd()

Validate XML against XSD.

private validateXsd(string $xmlContent, string $schemaPath) : array{valid: bool, errors: array>}
Parameters
$xmlContent : string

XML content.

$schemaPath : string

Trusted XSD path.

Return values
array{valid: bool, errors: array>}
On this page

Search results