Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6985] iOS: When Parsing large amounts of XML and referencing nodes, randomly a node will either be nulled, or change type!!

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-01-23T16:50:30.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sSprint 2012-02, Release 2.0.0, Release 1.8.1
ComponentsiOS
Labelsxml,, xmlparsing
ReporterAlan Leard
AssigneeMax Stepanov
Created2012-01-04T13:12:55.000+0000
Updated2012-01-23T16:50:30.000+0000

Description

We load a XML feed that has 400+ elements. Each has about 5 child nodes with numbers or a title, not much data. Looping over this XML, and converting it to JS randomly causes strange issues. First we get the element list using xmlDom.documentElement.getElementsByTagName('nodeName'), which works every time. Then we loop over those nodes, and for each child, we get the various sub node values we want and convert them to a JS object. During this loop, the current node value will randomly change from a TiDOMElement to either null, Object or TiDOMNodeList. Non of these are valid nodes, and thus subsequent node operations fail. The next iteration of the XML list will work fine. the function parseXML in the example file is passed the XHR responseXML object. In the retrieveNodeValue( nodeName, xmlNode) method, suddenly one of the calls the xmlNode passed in is null, Object or TiDOMNodeList - Not a NODE. All calls after this in the current loop will be the same,and then the next loop iteration it works fine.

Attachments

FileDateSize
crash during parsing.rtf2012-01-05T17:06:57.000+00001858
example.js2012-01-04T13:12:56.000+00001165
failed to parse in loop.rtf2012-01-05T17:06:57.000+000025001
XML Load Issues (1).zip2012-01-05T17:06:57.000+00001587870

Comments

  1. Matt Bryson 2012-01-05

    It was suggested that we use the responseText and parse it manually, (http://pastie.org/private/yrbidrdttmhxjpncrgxjpa) but that fails as well. I will upload an example project, and logs files so you can easily reproduce.
  2. Matt Bryson 2012-01-06

    The attached XML Load Issues Zip is a project that you can run to reproduce the issue - it's built following the common js approach. If you run the app, press the load button and watch the logs for output, you will see that half way through parsing, the XML node we are working on will either be nulled (which usually causes crashes), or changes type as mentioned in the post. It appears to fail about 1 in 5 loads. The feed we are loading is this : http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml – It updates once every 3 mins. If the data is loaded as the app boots, that causes a lot of instant crashes. When it does fail, the feed is still valid. I have attached two log files, one where it crashed, and one where it works, but some of the nodes fail to parse. In the Failed to Parse in Loop file, the two points of interest are: (our errors) [INFO] about to convert XML node to JS node number 6 [INFO] about to convert XML node to JS node number 7 [INFO] about to convert XML node to JS node number 8 {color:red} [ERROR] Retreiving Node name lat failed on XML object. XML object is [object Object] [ERROR] Retreiving Node name long failed on XML object. XML object is [object Object] [ERROR] Retreiving Node name nbBikes failed on XML object. XML object is [object Object] [ERROR] Retreiving Node name nbDocks failed on XML object. XML object is [object Object] {color} [INFO] about to convert XML node to JS node number 9 [INFO] about to convert XML node to JS node number 10 [INFO] about to convert XML node to JS node number 11 You see here that on node 8 of 400, the 'lat' XML node failed to be retrieved (as the TiDOMElement is reporting to be an Object Object). The subsequent child node lookups on this XML node fail (long, nbBikes, nbDocks). Then the next iteration, 9, works fine. Later, and this might be relevant, the log gets messed up. [INFO] about to convert XML node to JS node number 213 [INFO] about to convert XML node to JS node number 214{color:red} [INFO] about to convert XM[ERROR] Retreiving Node name nbEmptyDocks failed on XML object. XML object is [object Object] L node to JS node number 215{color} [INFO] about to convert XML node to JS node number 216 [INFO] about to convert XML node to JS node number 217 214 (or 215?) Fails for the same reason, but the log for 215 is mixed up with it. Not sure if this is an error with the loggin, or this could in some way indicate whats going on. It looks like the xml node we are working with is some how getting overwritten with other data – but you can see from the JS that this isn't possible from the JS side of things. With the log where it crashed, Ti just reported this [INFO] One moment, building ... [INFO] Titanium SDK version: 1.8.0.1 (12/22/11 13:09 fbdc96f) [INFO] iPhone Device family: iphone [INFO] iPhone SDK version: 5.0 [INFO] iPhone simulated device: iphone [INFO] Launching application in Simulator [INFO] Launched application in Simulator (2.99 seconds) [INFO] Found 5.0 patch installed [INFO] Application started [INFO] XML Load Issues/1.0 (1.8.0.1.fbdc96f) [INFO] Application has exited from Simulator
  3. Matt Bryson 2012-01-06

    Also, If you load the data as the app starts, it often crashes (at least in the simulator, not tried on device). If the load is user driven, or delay by a second, then it doesn't crash.
  4. Stephen Feather 2012-01-08

    Matt, Does this occur on a device as well?
  5. Cameron 2012-01-12

  6. Cameron 2012-01-12

    In agreement with the author, this issue is only affecting iOS on the emulator or on the device. This has not affected Android builds of the same exact app. Also as a complete shot in the dark (based on the date where the error cropped up) I was wondering if these fixes in the CI builds may be a source or related in some way: https://github.com/appcelerator/titanium_mobile/commit/bc6b5fce413c73bc0fb094c301b738dc75e01bcc and https://github.com/appcelerator/titanium_mobile/commit/364165a8345b968c03477a09cf9081f7b5f67381 Total shot in the dark
  7. Benjamin Jeanjean 2012-01-19

    This affect Ti SDK 1.7.X as well.
  8. Dustin Hyde 2012-01-23

    Closing as Fixed. SDK: 1.9.0.v20120121223134, 1.8.0.1.v20120119133134 Studio: 1.0.8.201201190907 OS: Lion Devices Tested: iPhone 5.0

JSON Source