Loading XML from sub directory

Hi All,

I’m in the process of moving my game over from another engine into Corona. My level editor of choice is GLEED2D, this outputs xml files. I’m using the XML parser found here (https://coronalabs.com/blog/2011/07/29/how-to-use-xml-files-in-corona/) by Jonathan Beebe.

The problem I am having is that I want my data to be structured into nice tidy sub folders, so my XML level files are in a structure like so: Media/Levels/StageName/ActName.xml

However, I don’t seem to be able to get the parser to read these files, the relevant lines of code are below.

Xml = require("Xml").newParser() local \_hXml = Xml.loadFile( "Media/Levels/" .. sStageName .. "/" .. sLevelName .. ".xml")

In the output consoles there seems to be an error stating that “Permission Denied” I can’t figure this out, the simulator is running in admin mode, the code in is my documents so is accessible. Any ideas would be a great help thank you.

Where are your XML files?  Are they in subfolders in your project folder (with your main.lua)?

There are four main sandbox directories for your app:

system.ResourcesDirectory – where you main.lua lives and any files in its folder (read only)

system.DocumentsDirectory – where any files your app creates are saved to.

system.CachesDirectory – Primarily an Apple iOS folder, where downloaded files are supposed to go.

system.TemporaryDirectory – tmp files (on Android, system.CachesDirectory goes here).

I don’t have that XML library code in front of me, but I suspect it’s defaulting to looking in system.DocumentsDirectory for your files, while they are in system.ResourcesDirectory.  Xml.loadFile should take an additional parameter to set the appropriate sandbox directory.

Hi Rob,

Thanks for the response.

The XML files are indeed stored inside of a sub-directory where the main.lua file is, they are nested within two three levels of sub directorty (Media/Levels/SpringTown/Act_1.xml).

I have tried setting the default base directory to system.ResourceDirectory and this didn’t help. The error states that permission is denied, but I don’t see how this is the case.

OK, I figured this out. I was trying to call the loadFile method as a function rather than an object method e.g. dot operator versus the colon candy!!

A meeting of the face and palm was enacted on a grand scale.

Thanks for the help though.

Where are your XML files?  Are they in subfolders in your project folder (with your main.lua)?

There are four main sandbox directories for your app:

system.ResourcesDirectory – where you main.lua lives and any files in its folder (read only)

system.DocumentsDirectory – where any files your app creates are saved to.

system.CachesDirectory – Primarily an Apple iOS folder, where downloaded files are supposed to go.

system.TemporaryDirectory – tmp files (on Android, system.CachesDirectory goes here).

I don’t have that XML library code in front of me, but I suspect it’s defaulting to looking in system.DocumentsDirectory for your files, while they are in system.ResourcesDirectory.  Xml.loadFile should take an additional parameter to set the appropriate sandbox directory.

Hi Rob,

Thanks for the response.

The XML files are indeed stored inside of a sub-directory where the main.lua file is, they are nested within two three levels of sub directorty (Media/Levels/SpringTown/Act_1.xml).

I have tried setting the default base directory to system.ResourceDirectory and this didn’t help. The error states that permission is denied, but I don’t see how this is the case.

OK, I figured this out. I was trying to call the loadFile method as a function rather than an object method e.g. dot operator versus the colon candy!!

A meeting of the face and palm was enacted on a grand scale.

Thanks for the help though.