Ребят, кто может подсказать, есть вот такой парсер погоды с yahoo, вот ссылка на XML:
http://weather.yahooapis.com/forecastrss?p=UPXX0016&u=f.
Теперь вопрос, мне нужно такой же, только их другого XML, насколько проблематично переделать исходный парсер под новые условия. Скажу сразу я не программист сайтов.
http://xml.weather.co.ua/1.2/forecast/23?dayf=5&userid=yoursite_com
function custom_parser( response, records ) {
var rss=parseXML( response ).documentElement;
var channel=rss.firstElementChild;
var day="today", map=[];
for ( var x=channel.firstElementChild; x!=null; x=x.nextElementSibling ) {
var name=x.localName;
if ( name=="location" ) {
map["city"]=x.getAttribute
40; "city" );
map["region"]=x.getAttribute
( "region" );
map["country"]=x.getAttribut
e( "country" );
} else if ( name=="units" ) {
map["temperatureUnits"]=x.ge
tAttribute( "temperature" );
map["distanceUnits"]=x.getAt
tribute( "distance" );
map["pressureUnits"]=x.getAt
tribute( "pressure" );
map["speedUnits"]=x.getAttri
bute( "speed" );
} else if ( name=="wind" ) {
map["windChill"]=x.getAttrib
ute( "chill" );
map["windDirection"]=x.getAt
tribute( "direction" );
map["windSpeed"]=x.getAttrib
ute( "speed" );
} else if ( name=="atmosphere" ) {
map["humidity"]=x.getAttribu
te( "humidity" );
map["visibility"]=x.getAttri
bute( "visibility" );
map["pressure"]=x.getAttribu
te( "pressure" );
map["rising"]=x.getAttribute
( "rising" );
} else if ( name=="astronomy" ) {
map["sunrise"]=x.getAttribut
e( "sunrise" );
map["sunset"]=x.getAttribute
( "sunset" );
} else if ( name=="item" ) {
for ( var y=x.firstElementChild; y!=null; y=y.nextElementSibling ) {
name=y.localName;
if ( name=="condition" ) {
map["text
4;]=y.getAttribute( "text" );
map["code
4;]=y.getAttribute( "code" );
map["tempera
ture"]=y.getAttribute( "temp" );
} else if ( name=="forecast" ) {
map[day+"_lo
w"]=y.getAttribute( "low" );
map[day+"_hi
gh"]=y.getAttribute( "high" );
map[day+"_te
xt"]=y.getAttribute( "text" );
map[day+"_co
de"]=y.getAttribute( "code" );
if ( day=="today" )
day="
;tomorrow";
}
}
}
}
remap( map, "code", "media", "title" );
remap( map, "today_code", "today_media", "today_title" );
remap( map, "tomorrow_code", "tomorrow_media", "tomorrow_title" );
records.push( map );
}
remap_table=[];
function remap( map, key_var, media_var, title_var ) {
if ( key_var in map ) {
var key=map[key_var];
if ( key in remap_table ) {
map[media_var]=remap_table[key
93;[0];
map[title_var]=remap_table[key
93;[1];
}
}
}
for ( var x=document.getElementById( "conditions" ).firstElementChild; x!=null; x=x.nextElementSibling ) {
var id=null, title=null, media=null;
for ( var y=x.firstElementChild; y!=null; y=y.nextElementSibling ) {
var name=y.localName;
if ( name=="id" )
id=y.textContent;
else if ( name=="image" )
media=y.firstElementChild.getAttributeNS(
; "http://www.w3.org/1999/xlink", "href" );
else if ( name=="text" )
title=y.textContent;
}
if ( id!=null )
remap_table[id] = [ media, title ];
}