Skip to content

DocumentSerializer

Turns the populated DOM back into the response body.

HTML serializes with saveHTML() and needs nothing else. XHTML is where the work is: DOM’s XML serializer produces output that browsers and validators object to in three separate ways, and each fix here is for one of them.

The fixes are only correct for a document that was parsed as HTML but is being written as XML, which is why each is conditional rather than unconditional. A document parsed as XML in the first place already has the namespaces and CDATA sections it needs.

final readonly class DocumentSerializer

SourceUtil/FormPopulation/DocumentSerializer.php

public function __construct(DOMDocument $document, bool $parsedAsXml, bool $properXhtml, bool $hadXmlProlog, bool $isUtf8): mixed

ParameterTypeDescription
$documentDOMDocument
$parsedAsXmlbool
$properXhtmlbool
$hadXmlPrologbool
$isUtf8bool

Returns mixed

MethodDescription
serialize(bool $xhtml, array<string, mixed> $cfg): string

public function serialize(bool $xhtml, array<string, mixed> $cfg): string

ParameterTypeDescription
$xhtmlbool
$cfgarray``<``string``, ``mixed``>

Returns string

ThrowsWhen
QuioteExceptionif a final regular-expression pass fails.