Note that there are some explanatory texts on larger screens.

plurals
  1. POPhoneGap read XML with FileReader?
    text
    copied!<p>I have an XML file on the SDCard, that is downloaded from a server. I am trying to open and read in that XML in order to use it within my app. I open and read it fine, but JQuery is freezing on parsing it.</p> <p>Once I get the file I do like so:</p> <pre><code>var reader = new FileReader(); reader.onloadend = function (evt) { parseXML(evt.target.result); }; reader.readAsText(file); </code></pre> <p>And then I begin parsing like so:</p> <pre><code>function parseXML(xml){ $(xml).find('recipe').each(function(){ </code></pre> <p>And it stops there. If I load the in-app XML using JQuery's ajax method it works fine. So, is there anything special about loading XML data using the FileReader in PhoneGap? </p> <p>UPDATE: OK, with much time and help from another dev, the issue appears to be a bug in PhoneGap. Specifically the FileTRansfer object.</p> <p>I was doing this:</p> <pre><code>var ft = new FileTransfer(); var dlPath = dataDir.fullPath + "/recipes.xml"; ft.download("http://design.mydomain.com/dave/humana/recipes/recipes.xml", dlPath, addedNewRecipes, addError); </code></pre> <p>And I'd get a trace within addedNewRecipes that the download succeeded. And it did... just not all of it. The file was truncated and that's what was causing the parseXML to fail. The entire XML file is about 90KB (~1600 lines) it was being truncated at maybe 50 lines. </p> <p>Replaced FileTransfer with a FileWriter object and it works now.</p> <p>PhoneGap/Cordova really is still beta isn't it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload