Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Cannot Get XML Parsing to work - about to give up and go to PhoneGap

I have wasted several days now trying to get XML parsing to work. As I check the community, it seems this is a known issue and was supposed to be fixed several times. I simply cannot use Titanium if I cannot parse an XML document containing elements, attributes, and nested elements and attributes. Can someone from appcelerator post the code to do this or tell me that it cannot be done currently?

— asked May 25th 2010 by Rick White
  • mobile
  • parsing
  • xml
0 Comments

5 Answers

  • Welcome to the world of a buggy and incomplete platform implementation and the land of no debugger :-)

    A very important point to keep in mind is that Titanium's DOMDocument implementation is not what you get in any normal browser. It's DOM2 implementation is incomplete, buggy, and wrong in some cases. It also doesn't support legacy DOM which real DOMDocument implementations support. One example is attributes and childNode array notation. If you have xml code that has node.childNode[x] your app will crash. If you have xml code that has node.attributes[z] your app will crash… Good luck!

    — answered May 26th 2010 by Kyle Quest
    permalink
    0 Comments
  • There is xml parsing example in kitchensink and many example codes posted in Q&A. I have an app in both Android Market and iPhone App store that uses xml parsing. What problem are you facing? Can you share your code, xml feed, issue/errors?

    — answered May 25th 2010 by Masood Nasir
    permalink
    0 Comments
  • Hi,

    If could give us an example of the XML you're trying to parse and the code you're using to try and parse it, we can help you out. :)

    It's working fine for me too. See the XML RSS demo in KitchenSink.

    — answered May 26th 2010 by Kosso
    permalink
    0 Comments
  • I am having the same/similar issue. My app worked fine using local images - referencing my "images array" variable. With the code below - no images are loaded and I get this error message:

    "Terminating in response to SpringBoard's termination.
    e of 0, meaning this view may not be visible."

    [WARN] [object TiUIScrollView] has an auto height value of 0, meaning this view may not be visible.

    —-XML FILE—–

    <?xml version="1.0" encoding="UTF-8"?>
       <channel>
        <image>
            <caption>Troop 1</caption>
            <path>101021-F-1328F-521.jpg</path>
        </image>
        <image>
            <caption>Troop 2</caption>
            <path>110111-F-1725G-503.jpg</path>
        </image>
        <image>
            <caption>Troop 3</caption>
            <path>110604-F-LU831-543.jpg</path>
        </image>
        <image>
            <caption>Troop 4</caption>
            <path>110825-F-XW651-520.jpg</path>
        </image>
        <image>
            <caption>Troop 5</caption>
            <path>081111-A-7377C-905.jpg</path>
        </image>
       </channel>
    

    —-TI Code—–

    var url="http://supportourtroops.sitegrafx.com/images.xml"; //  xml feed url
    var xhr = Titanium.Network.createHTTPClient();
    
    xhr.onload = function() {
        var doc = this.responseXML.documentElement;
            Ti.App.info(doc);
        var items = doc.getElementsByTagName("image");
            Ti.App.info(items);
        var x = 0;
        for (var i = 0; i < items.length; i++) {
            var item = items.item(i);
                Ti.App.info(item);
            images.push({
                path : item.getElementsByTagName("path").item(0).text,
                hasChild:true,
                content : item.getElementsByTagName("content").item(0).text
            });
        }
                Ti.App.info(images);
    }
    xhr.onerror = function(e) {
        // should do something more robust
        alert('Network error '+e.error);
    };
    
    xhr.open('GET',url);
    xhr.send();
    

    Adam.

    — answered December 8th 2011 by Adam Armstrong
    permalink
    0 Comments
  • Nevermind. Rick found his solution by switching over to Phonegap.

    — answered June 23rd 2010 by null null
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.