I am using the following function to convert XML to Json:
function XMLtoJSON($xml) {
$xml = file_get_contents($xml); // gets XML content from file
$xml = str_replace(array("\n", "\r", "\t"), '', $xml); // removes newlines, returns and tabs
// replace double quotes with single quotes, to ensure the simple XML function can parse the XML
$xml = trim(str_replace('"', "'", $xml));
$simpleXml = simplexml_load_string($xml);
return stripslashes(json_encode($simpleXml)); // returns a string with JSON object
}
I am trying to convert the following XML file:
https://www.comdinheiro.com.br/temp/COMDINHEIRO_GabrielVilella1146066400.xml
So my code is:
$myVar1 = XMLtoJSON("https://www.comdinheiro.com.br/temp/COMDINHEIRO_GabrielVilella1146066400.xml");
var_dump($myVar1);
Here is the var_dump result:
string(455) "{"controle":{"data_hora":"2017-05-12 20:26:47","usuario":"GabrielVilella","ferramenta":"ExtratoCarteira016"},"variaveis":{"nome_portfolio":"ApelidoTodos","data_ini":"2015-05-05","data_fim":"2016-08-12","cas_dec_q":"2","cas_dec_v":"2","discrimina_fundos":"0","discrimina_fundos_cvm":"0","discrimina_ativos":"1","discrimina_cadgeral":"0","data_fim_agenda":"2017-06-05","filtro_eventos":"todos","filtro_tipo_ativo":"todos","flag_export":"xml"},"resposta":{}}"
The conversion works properly. However it fails to fill the elements of "resposta":{}. No error message is shown. So I ask: Why "resposta":{} is empty?