{ "id": "61982", "key": "TIMOB-1350", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "11225", "name": "Release 1.5.0", "archived": true, "released": true, "releaseDate": "2010-12-14" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-04-17T01:55:56.000+0000", "created": "2011-04-15T02:50:10.000+0000", "priority": { "name": "Trivial", "id": "5" }, "labels": [ "domelement", "iphone", "xml" ], "versions": [], "issuelinks": [], "assignee": { "name": "rseagraves", "key": "rseagraves", "displayName": "Reggie Seagraves", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2011-04-17T01:55:56.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}
getElementById in the DOM proxy classes on iPhone fails,\nconsistently returning null instead of expected elements.
\nExample:
\nvar dom = Ti.XML.parseString('
Output on iPhone:
\n[INFO] #foo is null
The Android implementation gives expected output:
\n[INFO] [306,493] #foo is\nti.modules.titanium.xml.ElementProxy@43e66460
The bug:
\nThe XPath expression used to implement getElementById doesn't\nquote the string, leading to an XPath parse failure, and no\nresults:
\nNSArray *nodes = [document nodesForXPath:[NSString stringWithFormat:@\"//*[@id=%@]\",args] error:&error];
\n
\nSuggested fix is to add quotes:
\nNSArray *nodes = [document nodesForXPath:[NSString stringWithFormat:@\"//*[@id='%@']\",args] error:&error];
\n
\nProbably this should actually check for validity first as well,\nor else escape the string.
Provisional fix as a git branch:
\n\nhttp://github.com/brion/titanium_mobile/commit/14b88d7e760ed39146f5...
Adding \"[PATCH]\" to title.
Further fix to return a single node instead of a NodeList. There\nreally need to be some comprehensive unit tests on this module!
\n\nhttp://github.com/brion/titanium_mobile/commit/d725741f9ec569974990...
\nFull branch: http://github.com/brion/titanium_mobile/commits/getelementbyid
Assigning open patches from StatusNet to our support contact per\nrequest.
Nolan, any issues with this patch? Is there someone else we\nshould be assigning bugs to?
merged.
Hi,
\nI have the same problem that getElementById() returns null. I\nchanged the class TiDOMDocumentProxy.m, but there is still the same\nproblem.
\nvar f = Titanium.Filesystem.getFile(\"test.xml\");
\nvar textString = f.read();
\nvar textNode = textString.toString();
var xml = Ti.XML.parseString(textNode);
\nvar foo = xml.getElementById('node_one');
\nalert(foo);
Have you any ideas?
\nTiA,
\n-Marc
Tested on iPhone 4 (4.2) and on simulator running 4.0, 4.1, and\n4.2
\nSDK 1.5 (12/8/10) - r47a03e70
\nno problems found
\ncode:
\nvar win = Ti.UI.createWindow();\nvar xml = '<all>';\nxml += ' <one>hello</one>';\nxml += ' <two>world</two>';\nxml += ' <three id=\"foo\">hello world</three>';\nxml += '</all>';\nvar dom = Ti.XML.parseString(xml); \nvar foo = dom.getElementById('foo'); \nTi.API.info('#foo is ' + foo);\nTi.API.info('#foo\\'s text is ' + foo.text);\nwin.open();
\n
\ninfo: #foo is [object TiDOMElement]
\ninfo: #foo's text is hello world