[TIMOB-1350] Ti.XML.DOMDocument.getElementById fails on iPhone
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:55:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | iOS |
Labels | domelement, iphone, xml |
Reporter | Brion Vibber |
Assignee | Reggie Seagraves |
Created | 2011-04-15T02:50:10.000+0000 |
Updated | 2011-04-17T01:55:56.000+0000 |
Description
getElementById in the DOM proxy classes on iPhone fails, consistently returning null instead of expected elements.
Example:
var dom = Ti.XML.parseString('
Output on iPhone:
[INFO] #foo is null
The Android implementation gives expected output:
[INFO] [306,493] #foo is
ti.modules.titanium.xml.ElementProxy@43e66460
The bug:
The XPath expression used to implement getElementById doesn't
quote the string, leading to an XPath parse failure, and no
results:
NSArray *nodes = [document nodesForXPath:[NSString stringWithFormat:@"//*[@id=%@]",args] error:&error];
Suggested fix is to add quotes:
NSArray *nodes = [document nodesForXPath:[NSString stringWithFormat:@"//*[@id='%@']",args] error:&error];
Probably this should actually check for validity first as well, or else escape the string.
Provisional fix as a git branch:
http://github.com/brion/titanium_mobile/commit/14b88d7e760ed39146f5b59c6440aba23fec4a6a"> http://github.com/brion/titanium_mobile/commit/14b88d7e760ed39146f5...
Adding "[PATCH]" to title.
Further fix to return a single node instead of a NodeList. There really need to be some comprehensive unit tests on this module!
http://github.com/brion/titanium_mobile/commit/d725741f9ec56997499001b20f54ca25dde412a9"> http://github.com/brion/titanium_mobile/commit/d725741f9ec569974990...
Full branch: http://github.com/brion/titanium_mobile/commits/getelementbyid">http://github.com/brion/titanium_mobile/commits/getelementbyid
Assigning open patches from StatusNet to our support contact per request.
Nolan, any issues with this patch? Is there someone else we should be assigning bugs to?
merged.
Hi,
I have the same problem that getElementById() returns null. I changed the class TiDOMDocumentProxy.m, but there is still the same problem.
var f = Titanium.Filesystem.getFile("test.xml");
var textString = f.read();
var textNode = textString.toString();
var xml = Ti.XML.parseString(textNode);
var foo = xml.getElementById('node_one');
alert(foo);
Have you any ideas?
TiA,
-Marc
Tested on iPhone 4 (4.2) and on simulator running 4.0, 4.1, and 4.2
SDK 1.5 (12/8/10) - r47a03e70
no problems found
code:
info: #foo is [object TiDOMElement]
info: #foo's text is hello world