Hi,
I’m working on an app that strongly uses xml data, and from night to day it doesn’t work. The problem is: after I download the xml file from internet, and store it to the documents folder on the real device, the log says that the file exists, but when i parse the file using the “xml.lua” parser, it returns no parsed data.
I’m going completely crazy, because the same code works perfectly on iOS and the Corona Simulator.
Here is the code of the main.lua:
local xml = require( “xml” ).newParser()
– DESCARGAMOS EL XML e IMÁGENES DE LOS VÍDEOS
local function descargaMusica()
local path = system.pathForFile( “musica.xml”, system.DocumentsDirectory )
local fh, reason = io.open( path, “r” )
if fh then
print( “THE FILE EXISTS” )
else
print( "WARNING: file not found. Reason: " … reason ) – display failure message in terminal
end
local datos = xml:loadFile( “musica.xml”, system.DocumentsDirectory )
if datos then
print(“DATOS FOUND!”)
else
print(“DATOS NOT FOUND!!”)
end
local function imagenCargada( event )
if event.isError then
--print(“No hay red”)
else
local inicio = string.find( event.response, “caratulaMusica”)
local archivo = string.sub( event.response, inicio )
print( "La imagen es: " … archivo )
end
end
local infoMusica = {}
– Para cada “hijo” de la tabla datos, haz…
for i = 1, #datos.child do
– almacenamos cada hijo como una entrada de la tabla
print(“Entrando " … i … " veces.”)
infoMusica[i] = datos.child[i]
end
for i = 1, #infoMusica do
network.download( infoMusica[i].child[2].child[1].value, “GET”, imagenCargada, “caratulaMusica” … i … “.jpg”, system.DocumentsDirectory )
end
infoEventos = nil
end
local function gestionDeCargaMusica( event )
if event.isError then
--native.showAlert( “Error”, “Parece que no tienes conexión a Internet”, “OK” )
else
print( “¡Éxito! —> Cargando MÚSICA de Internet” )
print( event.response )
descargaMusica()
end
end
network.download( “http://www.aliatar.es/backstageCMS/02sesiones.xml”, “GET”, gestionDeCargaMusica, “musica.xml”, system.DocumentsDirectory )
I have set the proper permissions on the build.settings:
androidPermissions =
{
“android.permission.WRITE_EXTERNAL_STORAGE”, “android.permission.INTERNET”,
},
So, I don’t know what’s happening here. It sounds similar to the (http://developer.coronalabs.com/forum/2013/03/05/how-read-files-systemdocumentsdirectory-android-device)]issue described here
I have attached the project files.