[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.
Comments
- Brion Vibber 2011-04-15
- Brion Vibber 2011-04-15
Adding "[PATCH]" to title.
- Brion Vibber 2011-04-15
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
- Brion Vibber 2011-04-15
Assigning open patches from StatusNet to our support contact per request.
- Brion Vibber 2011-04-15
Nolan, any issues with this patch? Is there someone else we should be assigning bugs to?
- Jeff Haynie 2011-04-15
merged.
- MistX 2011-04-15
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 - Pedro Enrique 2011-04-15
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:var win = Ti.UI.createWindow(); var xml = '<all>'; xml += ' <one>hello</one>'; xml += ' <two>world</two>'; xml += ' <three id="foo">hello world</three>'; xml += '</all>'; var dom = Ti.XML.parseString(xml); var foo = dom.getElementById('foo'); Ti.API.info('#foo is ' + foo); Ti.API.info('#foo\'s text is ' + foo.text); win.open();
info: #foo is [object TiDOMElement]
info: #foo's text is hello world