Problem reading an XML file

You must Login before you can answer or comment on any questions.

Hi, I have a problem reading an XML file.

I do ~~~ var xmlFile = Ti.Filesystem.getFile(fileFolder, '1.xml'); if(xmlFile.exists()) { Ti.API.info(xmlFile.size); Ti.API.info(xmlFile.read().text); } ~~~

it give me about 5kb of size but return NULL for xmlFile.read().text XML file is ok, I have tested it on XML validators on the net.

Any idea of what could be the problem ?

Regards

— asked 8 months ago by Armindo Da Silva
6 Comments
  • Sorry for the formatting, don't know why it didn't take in account the tildes.

    — commented 8 months ago by Armindo Da Silva

  • What is fileFolder? I have it working in a test project where I pass Ti.Filesystem.resourcesDirectory as the first param with 1.xml in the Resources folder. Make sure you refresh the project, clean it (Project -> Clean...) and rebuild. Failing that, post your TiSDK version and what platform you're building to.

    — commented 8 months ago by Daniel Sefton

  • Sorry for late reply : file folder is like that

    var fileFolder;
    if(isAndroid) {
        if (Titanium.Filesystem.isExternalStoragePresent()) {
            fileFolder = Ti.Filesystem.getExternalStorageDirectory();
        } else {
          fileFolder = Titanium.Filesystem.applicationDataDirectory;//Ti.Filesystem.applicationDataDirectory;
        };
    } else {
        fileFolder = privateDocumentsDirectory();
    }
     
    var folder =Titanium.Filesystem.getFile(fileFolder);
        if(!folder.exists()){
            folder.createDirectory(); // always return 0 :(
        }
    but if I try to read a text file it is ok, that puzzles me... I'm using SDK 2.1.3 GA and building for IOS 6 and testing on iPhone 5 simulator. Already try to rebuild, same problem...

    — commented 8 months ago by Armindo Da Silva

  • Show 3 more comments

1 Answer

Accepted Answer

yes it was a UTF-8 problem, now the XML files are UTF-8 and the problem is solved...

Your Answer

Think you can help? Login to answer this question!