Json_decode / encode on simplexmlelement adds arrays instead of empty strings

when loading an XML document and converting to an array using

json_decode(json_encode(simplexml_load_string($xml)), 1); 

All empty xml nodes ( <node /> ) are converted to array (). I would like them to be an empty string. Do I need to go through all the elements and replace each empty node with something else?

I am loading an XML document using $xml = new SimpleXmlElement($this->feed_uri, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG , true);

+4
source share
1 answer

You cannot do this automatically. Thus, after the conversion, you will need to replace the empty arrays with empty strings.

By the way, LIBXML_NOEMPTYTAG makes no sense here:

This option is currently only available in the DOMDocument :: save and DOMDocument :: saveXML functions. http://ua1.php.net/manual/en/libxml.constants.php

+2
source

All Articles