4

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 instead. Do I need to go through all elements and replace each empty node with something else?

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

1 Answer 1

2

You can not accomplish that automatically. So you would need to replace empty arrays with empty strings after the conversion.

By the way, LIBXML_NOEMPTYTAG makes no sense here:

This option is currently just available in the DOMDocument::save and DOMDocument::saveXML functions. https://www.php.net/manual/en/libxml.constants.php

Sign up to request clarification or add additional context in comments.

1 Comment

bleh, that sucks. the libxml_noemptytag was a last ditch effort I did read the docs but figured, just in case I'd try it, and thought maybe it may spark some creativity in someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.