1<?php
2function createElement($doc, $name, ?string $value = null) {
3    $element = $doc->createElement($name);
4    if ($value) $element->textContent = $value;
5    return $element;
6}
7
8function createElementNS($doc, $ns, $name, ?string $value = null) {
9    $element = $doc->createElementNS($ns, $name);
10    if ($value) $element->textContent = $value;
11    return $element;
12}
13