Ajay Y Ajay Y - 1 year ago 108
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.

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download