Php simplexml without xml ad tag

I am using SimpleXML to generate XML. When i use:

new SimpleXMLElement('<row></row>'); 

SimpleXML generates this XML:

 <?xml version="1.0"?>\n<row/> 

But I only need:

 <row/> 

I only need this because I will include it in another XML.

How can I only generate a string tag in a SimpleXML object?

+5
source share
1 answer

As stated in the previous Q & A:

You can import SimpleXMLElement into a PHP document object model (DOM) extension and output it there as XML, since this extension can be output without an XML declaration.

Import to 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); 

Conclusion:

 <row/> 

You can also run this code yourself on the Internet: https://eval.in/302096

Hope this helps you.

+2
source

Source: https://habr.com/ru/post/1211173/


All Articles