Search code examples
androidiosxmlappceleratorappcelerator-titanium

Appcelerator Titanium - XML parse in Android not working


As the title says, in Android I can not get the XML parse to work. In iOS works correctly. This code is from Appcelerator and this is the link to the documentation page: http://docs.appcelerator.com/platform/latest/#!/guide/Working_with_XML_Data

    var win = Titanium.UI.createWindow({
        backgroundColor:'#fff'
    });

    var data = [];
    var table = Ti.UI.createTableView({backgroundColor:"red"});
    win.add(table);

    var url="http://apod.nasa.gov/apod.rss"; //  rss feed url
    var xhr = Titanium.Network.createHTTPClient();

    xhr.onload = function() {
        // Data is returned from the blog, start parsing
        var doc = this.responseXML.documentElement;

        // begin looping through blog posts
        var items = doc.getElementsByTagName("item");
        for (var i=0;i<items.length;i++) {
            data.push({
                title: items.item(i).getElementsByTagName("title").item(0).text
            });
        }
        table.data = data;
    };
    xhr.onerror = function(e) {
        // should do something more robust
        alert('Network error '+e.error);
    };

    xhr.open('GET',url);
    xhr.send();

    win.open();

The result is different as you can see in this image IOS and Android example image

I'm using Titanium SDK 6.1.0.GA

Has the same happened to anyone else yet?

Thank you


Solution

  • Replace text with textContent:

        data.push({
            title: items.item(i).getElementsByTagName("title").item(0).textContent
        });