{ "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.

\n

Example:
\nvar dom = Ti.XML.parseString('

\n'); var foo = dom.getElementById('foo'); Titanium.API.info('#foo is\n' + foo);\n

Output on iPhone:
\n[INFO] #foo is null

\n

The Android implementation gives expected output:
\n[INFO] [306,493] #foo is\nti.modules.titanium.xml.ElementProxy@43e66460

\n

The bug:

\n

The XPath expression used to implement getElementById doesn't\nquote the string, leading to an XPath parse failure, and no\nresults:

\n
\nNSArray *nodes = [document nodesForXPath:[NSString stringWithFormat:@\"//*[@id=%@]\",args] error:&error];\n
\n

Suggested fix is to add quotes:

\n
\nNSArray *nodes = [document nodesForXPath:[NSString stringWithFormat:@\"//*[@id='%@']\",args] error:&error];\n
\n

Probably this should actually check for validity first as well,\nor else escape the string.

{html}", "attachment": [], "flagged": false, "summary": "Ti.XML.DOMDocument.getElementById fails on iPhone", "creator": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "125419", "author": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Provisional fix as a git branch:
\n\nhttp://github.com/brion/titanium_mobile/commit/14b88d7e760ed39146f5...

{html}", "updateAuthor": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:11.000+0000", "updated": "2011-04-15T02:50:11.000+0000" }, { "id": "125420", "author": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Adding \"[PATCH]\" to title.

{html}", "updateAuthor": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:11.000+0000", "updated": "2011-04-15T02:50:11.000+0000" }, { "id": "125421", "author": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

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...

\n

Full branch: http://github.com/brion/titanium_mobile/commits/getelementbyid

{html}", "updateAuthor": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:11.000+0000", "updated": "2011-04-15T02:50:11.000+0000" }, { "id": "125422", "author": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Assigning open patches from StatusNet to our support contact per\nrequest.

{html}", "updateAuthor": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:11.000+0000", "updated": "2011-04-15T02:50:11.000+0000" }, { "id": "125423", "author": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Nolan, any issues with this patch? Is there someone else we\nshould be assigning bugs to?

{html}", "updateAuthor": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:11.000+0000", "updated": "2011-04-15T02:50:11.000+0000" }, { "id": "125424", "author": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

merged.

{html}", "updateAuthor": { "name": "jhaynie", "key": "jhaynie", "displayName": "Jeff Haynie", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:11.000+0000", "updated": "2011-04-15T02:50:11.000+0000" }, { "id": "125425", "author": { "name": "mistx", "key": "mistx", "displayName": "MistX", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Hi,

\n

I have the same problem that getElementById() returns null. I\nchanged the class TiDOMDocumentProxy.m, but there is still the same\nproblem.

\n

var f = Titanium.Filesystem.getFile(\"test.xml\");
\nvar textString = f.read();
\nvar textNode = textString.toString();

\n

var xml = Ti.XML.parseString(textNode);
\nvar foo = xml.getElementById('node_one');
\nalert(foo);

\n

Have you any ideas?

\n

TiA,
\n-Marc

{html}", "updateAuthor": { "name": "mistx", "key": "mistx", "displayName": "MistX", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:12.000+0000", "updated": "2011-04-15T02:50:12.000+0000" }, { "id": "125426", "author": { "name": "penrique", "key": "penrique", "displayName": "Pedro Enrique", "active": false, "timeZone": "America/Los_Angeles" }, "body": "{html}

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:

\n
\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
\n

info: #foo is [object TiDOMElement]
\ninfo: #foo's text is hello world

{html}", "updateAuthor": { "name": "penrique", "key": "penrique", "displayName": "Pedro Enrique", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:50:12.000+0000", "updated": "2011-04-15T02:50:12.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }