Titanium Community Questions & Answer Archive

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

Parsing XML struct

I am seeking some help on parsing xml returned from an xmlrpc call.
An example result is a structure of name/value pairs:

<value><string>Dr Bar</string></value>

I have tired the following but get null so I suppose I am over simplifying.

var result = this.responseText;
Titanium.API.info('Received: '+result);
var xml = Ti.XML.parseString(result);
var structList = xml.documentElement.getElementsByTagName("struct");



Does give me "id" but


Gives me zip.

Ok, correction again..


Gives me "8".
I just need a more efficient way to do this as the structures returned by various calls are not all the same.

Ok, now I am this far I can figure it out.

New question: how do you delete a dumb question so it does not clutter up the Q&A?


— asked March 18th 2010 by rob stevens
1 Comment
  • I had a lot of trouble parsing XMLRpc in this environment. I found a decent parser called Mimic which took the XML and parsed into a massive array using JS. However this took up so much memory since the array was so massive that I ended up abandoning this part of the project and using a webview instead.

    — commented August 29th 2011 by dave fletcher

4 Answers

  • Here's a solution:

    var result = this.responseText;
    var xml = Ti.XML.parseString(result);
    var params = xml.documentElement.getElementsByTagName("member");
    var name = xml.documentElement.getElementsByTagName("name");
    var value = xml.documentElement.getElementsByTagName("string");
    var data = [];
    for (var i=0;i<params.item.length;i++) {
        Ti.API.log('Param '+i+': Name: '+n.item(i).text);
        Ti.API.log('Param '+i+': Value: '+v.item(i).text);
        // Add to array

    Your XML doc could have a better structure, which would make it easier to parse. Here's a screenshot.

    If you use responseXML, your XML needs to be validated (ie, DTD).

    — answered March 18th 2010 by TZ Martin
    1 Comment
    • This answer helped me a lot, but I saw an issue in the for condition: params.item.length … To fix this, just do params.length

      Thanks for the great topic guys!

      — commented September 8th 2011 by Joseandro Luiz
  • One thing you can do is to also try using : var xml = this.responseXML;

    Instead of using Ti.XML.parseString from the result.

    — answered March 18th 2010 by Kosso
  • This isnt a dumb post - it got me over my brain block with xml in this environment!

    — answered July 22nd 2011 by Steve Hovey
  • I have an XML with this structure:

    <?xml version="1.0" encoding="UTF-8"?>
            <Account ID="248" Name="wertyu" />
            <Account ID="251" Name="hgdfh" />
            <Account ID="249" Name="wertyui" />
            <Rol ID="14" Name="SentDocsAsign" />
            <Rol ID="15" Name="RcvDocsAsign" />
            <Rol ID="30" Name="SenderUser" />

    I parsed all the User data, but how can i parse the Accounts and the Roles nodes?

    — answered December 17th 2012 by Alex Lerma
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.