Ajay Y Ajay Y - 2 months ago 20
Javascript Question

I want to access the attribute of xml tag using javascript, how I can access it?

I am getting the XML data from link "http://weather.yahooapis.com/forecastrss?p=CHXX0008&u=unit"

Following is my javscript code :

type: "GET",
url: "http://weather.yahooapis.com/forecastrss?"+"p="+zipcode+"&u=c",
dataType: "xml",
success: function(xml) {

} } );

enter image description here

Using above code I am trying to access "city" attribute of tag "yweather:location". How can I accesss? Please check the XML data using link provided.

success: function(xml) {
                var loc = xml.getElementsByTagNameNS('http://xml.weather.yahoo.com/ns/rss/1.0', 'location');
                var city = loc[0].getAttribute('city');

Hope this helps you. Mark as answer if you are satisfied.