Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3116] getElementsByTagName("text").item(0).text now has spotty functionality

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2011-12-19T16:10:28.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labels1.8.0.1, 1.9
ReporterCameron
AssigneePaul Dowsett
Created2011-12-10T06:55:26.000+0000
Updated2016-03-08T07:48:10.000+0000

Description

Obtaining XML elements using the following code has
var doc = xhr.responseXML.documentElement;
    
    var items = doc.getElementsByTagName("entry");

    for (var c=0;c<items.length;c++)
    {
        var item = items.item(c);
	var authorname = item.getElementsByTagName("author").item(0).text;
	var authorid = item.getElementsByTagName("authorid").item(0).text;
	var info = item.getElementsByTagName("text").item(0).text;
    }
The most recent build of 1.8 and 1.9 starting around December 8 these types of calls now have sporadic functionality. There is no direct pattern I can pick up yet as to why or which ones do not work, it seems almost random. The precise error code generated is: "Result of expression 'item.getElementsByTagName' [undefined] is not a function." I have checked and made sure the source XML document contains all those XML elements listed, and in fact, with earlier builds of 1.8 or 1.7 this code works perfectly fine on the same exact document. This issue only affects iOS. The same code runs just fine on Android with the latest CI builds.

Comments

  1. Ivan Skugor 2011-12-10

    You should post test example that can be run without any modifications. Anyway, your code shouldn't work in any case. In "for" loop you misspelled "items", there is "item" which is undefined variable and you should get "ReferenceException". So, instead of "item" there should be "items[c]". Also, "responseXML.documentElement" sometimes doesn't work on Android, the workaround is to parse XML string from XHR response, something like this:
       var doc = Ti.XML.parseString(xhr.responseXML.toString());
       
    Hope this helps. Cheers.
  2. Cameron 2011-12-10

    Ivan, Sorry I forgot one line of code while simplifying it for the ticket. "var item = items.item(c);" which creates the item variable, i've fixed the code in the original ticket now. As for responseXML, it seems to be functioning as far as I can tell, as the error that will be thrown may be on the second or third getElementsByTagName request at random. So for example, var authorname = item.getElementsByTagName("author").item(0).text will work just fine, whereas var info = item.getElementsByTagName("text").item(0).text will not work, or vice versa. The strange part is that I upload from the CI builds daily, and this has never been an issue until around the December 7-8 1.8.0.1 builds until now. And my app works primarily using XML data, so the issue was immediatly obvious as a change. Even right now I can run the app using a December 7 build, and its running great, however using last night's build its broken.
  3. Ivan Skugor 2011-12-10

    Ah yes, should be "items.item(c)", I think "items[c]" won't work here (but works in browser). Anyway, to increase chance of your ticket's acceptance, you should check this: http://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report (if you look around TC, you'll see that there are tickets with great descriptions and test cases and yet are not accepted, so good luck with yours)
  4. Cameron 2011-12-10

    Ivan, thank you. I will read that over. Hopefully this is accepted as this is quite real and reproducible as I switch between the builds and between iOS and Android.
  5. Cameron 2011-12-12

  6. Cameron 2011-12-13

    Just another update in the hope that this is addressed. I have the same identical code, same CI build version (latest 1.9) run between iOS and ANdroid emulators, and the issue still pops up on the iOS version, but not the Android version. Something is definitely wrong and went wrong around December 7-8
  7. Cameron 2011-12-14

  8. Cameron 2011-12-14

    Maybee these code changes have something to do with it as well, since around this time is when everything broke: https://github.com/appcelerator/titanium_mobile/commit/bc6b5fce413c73bc0fb094c301b738dc75e01bcc https://github.com/appcelerator/titanium_mobile/commit/364165a8345b968c03477a09cf9081f7b5f67381
  9. Paul Dowsett 2011-12-19

    Thank you for raising this ticket. If you are able to provide all the information described in the [JIRA Ticket Checklist](http://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist) guidelines, *in the correct fields and using the right format*, I will be able to escalate it to the core team. Please click *edit* to amend the body of the ticket, rather than adding a comment. As Ivan rightly states, I am afraid I need a test case that runs without modification, which can be used to reproduce the issue and test the resolution once fixed. I will mark this resolved for now. Please reopen when the ticket is complete. Thanks in advance.
  10. Paul Dowsett 2012-02-17

    Closing due to inactivity. If this issue still exists, please raise a new ticket, including all the information in the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist) to ensure that we can escalate it quickly. Read [How to Submit a Bug Report](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report) if you have not read it before, and always start a ticket using the [JIRA Ticket Template](https://wiki.appcelerator.org/display/guides/JIRA+Ticket+Template). Thanks in advance

JSON Source