I´m wondering how to return a empy value into my "attribute" in case the final user doesn´t fill in the form field called "name" and leave it blank.
My actual code:
$domElement = $domDocument->createElement('attribute', $posted_data['name']);
$domAttribute = $domDocument->createAttribute('domainname');
$domAttribute->value = 'Name';
$domElement->appendChild($domAttribute);
Desired ouput in case of empty input in the form field "name":
<attribute domainname="Name"></attribute>
Current output based on the actual code:
<attribute domainname="Name"/>
As you can see, it´s not being completed by </attribute>
but just />
Any clue?
You can use const LIBXML_NOEMPTYTAG
<?php
$domDocument = new DOMDocument;
$domElement = $domDocument->createElement('attribute');
$domAttribute = $domDocument->createAttribute('domainname');
$domAttribute->value = 'Name';
$domElement->appendChild($domAttribute);
echo $domDocument->saveXML($domElement, LIBXML_NOEMPTYTAG), PHP_EOL;
http://php.net/manual/en/libxml.constants.php#constant.libxml-noemptytag