0

I have an xml data and i need to convert this xml into an array ,i use the bellow PHP code,

$xml                       = new SimpleXMLElement($data); // $data contain the xml data
$transaction_result        = json_decode(json_encode($xml),true);

This is working ,but the problem is.

If a node in xml is empty,That value automatically converted as an empty array.Is it possible to remove the empty array?

Example: if the node in xml is <name></name> then the result become

array('name'=>array());

My expected result is

array('name'=>'');

How is it possible to overcome this issue?

2
  • You can try passing some options to SimpleXMLElement to filter out empty nodes, for example LIBXML_NOBLANKS see: php.net/manual/en/libxml.constants.php Commented Jul 11, 2016 at 13:36
  • 1
    I tried new SimpleXMLElement($data,LIBXML_NOBLANKS) ,but getting the same result Commented Jul 11, 2016 at 13:44

0

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.