Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-862] on android cdata from xml returns blank

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:54:28.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.4.0
ComponentsAndroid
Labelsandroid, defect, xml
ReporterMasood
AssigneeDon Thorp
Created2011-04-15T02:38:01.000+0000
Updated2011-04-17T01:54:28.000+0000

Description

Example XML feed

<title>some title</title>
<description><![CDATA[Some text]]></description>

the following code works in iphone but not on android to extract description:

var title = item.getElementsByTagName("title").item(0).text;
var description = item.getElementsByTagName("description").item(0).text;

Comments

  1. Masood 2011-04-15

    found answer on q&a, this works on android:

       var description = item.getElementsByTagName("description").item(0).firstChild.nodeValue.text;
       

    please close this ticket. thanks.

  2. Brion Vibber 2011-04-15

    This bug is legitimate, and also affects other sorts of situations such as embedded child elements:

           Ti.XML.parseString('<div>foo <span>bar</span> baz</div>').documentElement.text
       

    gives 'foo bar baz' as expected on iPhone;
    gives 'foo baz' on Android.

    The bug is in ElementProxy:

           public String getText() {
                   StringBuilder sb = new StringBuilder();
                   NodeList children = element.getChildNodes();
                   for (int i = 0; i < children.getLength(); i++)
                   {
                           Node child = children.item(i);
                           if (child.getNodeType() == Node.TEXT_NODE) {
       

    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

                                   sb.append(((Text)child).getNodeValue());
                           }
                   }
       
                   return sb.toString();
           }
       

    That explicit check for text child nodes fails to include text content from character entities, CDATA sections, or child elements which themselves contain text.

  3. Marshall Culpepper 2011-04-15

    (from [9b3c7fa6daba96d532b223be26f7746aa97e0231]) also handle elements, entities, and CDATA sections in ElementProxy.getText() [#862 state:resolved] http://github.com/appcelerator/titanium_mobile/commit/9b3c7fa6daba96d532b223be26f7746aa97e0231"> http://github.com/appcelerator/titanium_mobile/commit/9b3c7fa6daba9...

  4. Brion Vibber 2011-04-15

    Confirmed that fixes my problem case -- thanks!

JSON Source