I have an XML file in which some tags can sometimes be empty. When I read this file using PHP and encode it using json_encode, JSON converts all my empty tags to empty objects, while I prefer them exactly the same as they are, empty lines. What is the best way to stop / avoid this conversion?
EDIT: I prefer not to remove these tags from XML, because for me there is a difference between writing an XML without a specific tag and writing an XML so that this tag is empty.
EDIT 2: sample input:
<Family> <name>aaa</name> <adults>3</adults> <kids /> </Family>
Tag
kids is empty
I would like to get coding results as
Family[1].name = 'aaa'; Family[1].adults = 3; Family[1].kids = '';
I get:
Family[1].name = 'aaa'; Family[1].adults = 3; Family[1].kids = Object(); //empty
EDIT3:
My implementation is very simple:
in php
$xml = simplexml_load_file($filepath); echo json_encode($xml, JSON_NUMERIC_CHECK);
in javascript
objJson = $.parseJSON(xmlhttp.responseText); .... d["name"] = objJson.Family[i].name; d["adults"] = objJson.Family[i].adults; d["kids"] = objJson.Family[i].kids;
source share