DOM Errors

During parsing, documents with problems may return potential issues reported by libXML as Inphinit\Dom\DomException.

Define severity levels

FATAL

use Inphinit\Dom\Document; Document::setSeverityLevels(Document::FATAL);

A document that is not well-formatted will return a fatal error as an Inphinit\Dom\DomException. This also includes OOM and I/O errors, resource limit exhaustion, unexpected errors from other libraries and invalid argument errors.

WARNING

use Inphinit\Dom\Document; Document::setSeverityLevels(Document::WARNING);

ERROR

use Inphinit\Dom\Document; Document::setSeverityLevels(Document::ERROR);

It will throw recoverable errors as an Inphinit\Dom\DomException, for example:

  • Namespace errors.
  • Validity errors when validating.
  • Certain undeclared entities.
  • ID uniqueness and xml:id errors.

Report all

Throw an exception for warnings, errors, and fatal errors that may occur during parsing:

use Inphinit\Dom\Document; Document::setSeverityLevels(Document::ERROR | Document::FATAL | Document::WARNING);

Parse error

Documents with problems, according to the defined degree of severalness, will issue errors if problems are found in the document. For local documents, the exception will point to the exact line that presents the problem, example:

use Inphinit\Dom\Document; // parse XML $handle = new Document(Document::XML); $handle->load('/foo/bar/sample.xml', true);

sample.xml:

<?xml version="1.0" encoding="UTF-8"?> <contact> <sample>test</sample> <foo:name>Foo bar baz</foo:name> <baz:phone>(000) 0000-xxxx</baz:phone> </contact>

Output:

Fatal error: Uncaught Inphinit/Dom/DomException: Namespace prefix foo on name is not defined in /foo/bar/sample.xml:4 Stack trace: #0 /home/application/system/vendor/inphinit/framework/src/Inphinit/Dom/Document.php(214): Inphinit/Dom/Document->raise(3) #1 /home/application/system/dev.php(482): Inphinit/Dom/Document->load('/foo/bar/sample.xm...', true) #2 /home/application/system/vendor/inphinit/framework/src/Inphinit/App.php(223): {closure:{closure:/home/application/system/dev.php:358}:478}(Object(Inphinit/Diagnostics/App), NULL) #3 /home/application/index.php(8): Inphinit/App->exec() #4 {main} thrown in /foo/bar/sample.xml on line 4

If you are in development mode and have added $debug->setErrorView('debug.error');, a similar screen will be displayed:

Go to homepage
Star us on Github