Q:

Parsing XML in Javascfipt

Ok I am trying to parse an XML from a get request in Javascript. 
This is how the XML looks like 
<markers>
<marker>
<name>
<![CDATA[ Pan Africa Market ]]>
</name>
<address>
<![CDATA[ 1521 1st Ave, Seattle, WA ]]>
</address>
<lat>47.608940</lat>
<lng>-122.340141</lng>
<price>150</price>
<type>restaurant</type>
</marker>
</markers>

I am trying to push the marker into an array so I can access it later (I am building a google maps marker with it)
In the result var I save the response from the get request (This is working perfect I know it cause I can alert the "params.length")
var result = this.responseText;

var xml = Ti.XML.parseString(result);
var items = xml.documentElement.getElementsByTagName("marker");

var name = xml.documentElement.getElementsByTagName("name");
var value = xml.documentElement.getElementsByTagName("address");

var data = [];

for (var i=0;i<items.length;i++) {
         alert(items.item(i).getElementsByTagName("price").item(0).text);

}

I can alert the items prices (1 by 1 of course), but the question is how can I save that so I can access it later.
I red that I have to push it into the data variable in the for loop but I just dont know how.
Thanks in advance.
PD Im using it in Appcelerator. (I think this is not very important)

A:

Try this:
var markers = xml.documentElement.getElementsByTagName("marker");

var data = [];

for (var i=0;i<markers.length;i++) {
    console.log(markers[i].getElementsByTagName("name")[0]);
    data.push({
        name: markers[i].getElementsByTagName("name")[0].textContent,
        address: markers[i].getElementsByTagName("address")[0].textContent 
    })
}
// data is now [{name: "...", address: "..." }]

See working fiddle: http://jsfiddle.net/nrabinowitz/XZnXn/
For more on navigating a DOM structure in Javascript, you might want to look at the MDN DOM Reference.

