Titanium Community Questions & Answer Archive

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

Problem with parsing XML

Hello,

i try to parse a XML-String but, that I receive via a HTTP-Client. No problems so far.

var ManifestXML = this.responseText;
var xml_as_dom = Titanium.XML.parseString(ManifestXML);

Then I try to get a node - works too

var my_items = xml_as_dom.getElementsByTagName("item");

with the length-attribute I can see, that 7 nodes are being returned, which is correct. But now I can not treat the returned variable as array.

The following line does not work

alert(my_items[0]); //returns 'undefined'

Has anybody a suggestion?

I use the mobile SDK 1.0.0 for iPhone

Thanks in advance,

Carsten

— asked March 10th 2010 by Carsten Mohr
  • 1.0
  • iPhone
  • XML
0 Comments

2 Answers

  • OK, found an answer…

    The returned variable (my_items) is not an array but an object (type: TiDomNodeList)

    You can access it by using

    my_items.item(0); // 1,2,3,4,5,.....
    
    — answered March 10th 2010 by Carsten Mohr
    permalink
    0 Comments
  • On shortcut, just use the property this.responseXML to get the DOMDocument directly.

    — answered March 10th 2010 by Jeff Haynie
    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.