I use SimpleXML to generate XML. When I use :
new SimpleXMLElement('<row></row>');
SimpleXML generates this XML :
<?xml version="1.0"?>\n<row/>
But I need only :
<row/>
I need only it because I will include it to another XML.
How can I generate only row tag in an SimpleXML Object ?
As has been outlined in the earlier Q&A:
You can import the SimpleXMLElement into the PHP Document Object Model (DOM) extension and output it there as XML because that extension can output without the XML declaration.
Importing into dom works with the dom_import_simplexml
function.
Example:
$xml = new SimpleXMLElement('<row></row>');
$domxml = dom_import_simplexml($xml);
echo $domxml->ownerDocument->saveXML($domxml->ownerDocument->documentElement);
Output:
<row/>
You can also run this code your own online here: https://eval.in/302096
Hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With