$root = new SimpleXMLElement('<' . $key . '/>');
self::fromArray($value, $root, $remove_header, $namespaces, false);
} else {
- $root = new SimpleXMLElement('<' . $key . '>'.self::escape($value).'</' . $key . '>');
+ $root = new SimpleXMLElement('<' . $key . '>' . self::escape($value ?? '') . '</' . $key . '>');
}
$dom = dom_import_simplexml($root)->ownerDocument;
}
if (!is_array($value)) {
- $element = $xml->addChild($key, self::escape($value), $namespace);
+ $element = $xml->addChild($key, self::escape($value ?? ''), $namespace);
} elseif (is_array($value)) {
$element = $xml->addChild($key, null, $namespace);
self::fromArray($value, $element, $remove_header, $namespaces, false);
foreach ($attributes as $key => $value) {
$attribute = $doc->createAttribute($key);
- $attribute->value = self::escape($value);
+ $attribute->value = self::escape($value ?? '');
$element->appendChild($attribute);
}
return $element;
/**
* Create an XML and append it to the parent object
*
- * @param DOMDocument $doc XML root
+ * @param DOMDocument $doc XML root
* @param object $parent parent object
* @param string $element XML element name
* @param string $value XML value