Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3333230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:46:25+00:00 2026-05-17T23:46:25+00:00

I’m quite new to javascript, but have managed to write a working xml function

  • 0

I’m quite new to javascript, but have managed to write a working xml function 🙂

I was hoping someone could please give me a rundown of how to optimise the function. At present there’s a different function for each state’s weather, but I was hoping I could simplify this somehow.

Code is pasted here: http://pastie.org/private/ffuvwgbeenhyo07vqkkcsw

Any help is greatly appreciated.
Thank you!

EDIT: ADDING CODE EXAMPLES OF BOTH XML FEEDS:

Function 1 (UV): http://pastie.org/private/jc9oxkexypn0cw5yaskiq

Function 2 (weather): http://pastie.org/private/pnckz4k4yabgvtdbsjvvrq

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:46:26+00:00Added an answer on May 17, 2026 at 11:46 pm

    I would suggest you create an array that holds the UV element IDs, suffixes and weather station ids (stationid)

    var areas = [
         {id:'sydney',suffix:'syd',stationid:'YSSY'},
         {id:'melbourne',suffix:'mel',stationid:'YMML'},
         {id:'brisbane',suffix:'bri',stationid:'YBBN'},
         {id:'perth',suffix:'per',stationid:'YPPH'},
         ...
     ]
    

    and then for the UV

    // FUNCTION 1 - UV
    function getUV() {
    
        // BEGIN AUSTRALIAN UV FUNCTION
    
        $.get('http://www.arpansa.gov.au/uvindex/realtime/xml/uvvalues.xml', function(d) {
    
            //SYDNEY UV
                 $(areas).each(function(){
                var area = this;
            $(d).find('location#'+area.name).each(function(){
    
                var $location = $(this); 
                var uvindex = $location.find('index').text();
    
                var areauv = areauv += '<span>' + uvindex + '</span>' ;
                $('#uv-'+area.suffix).empty().append($(areauv)); // empty div first
    
                if (uvindex <= 2.0) {
                    $('#risk-'+area.suffix).empty().append('Low');
                    $('#curcon-'+area.suffix).empty().append('You can safely stay outdoors and use an SPF 15 moisturiser.');
                } else if (uvindex <= 5.0) {
                    $('#risk-'+area.suffix).empty().append('Moderate');
                    $('#curcon-'+area.suffix).empty().append('Wear protective clothing outdoors and use an SPF 15 or SPF 30 moisturiser.');
                } else if (uvindex <= 7.0) {
                    $('#risk-'+area.suffix).empty().append('High');
                    $('#curcon-'+area.suffix).empty().append('Wear protective clothing, limit your time outdoors and use an SPF 30 moisturiser.');
                } else if (uvindex <= 10.0) {
                    $('#risk-'+area.suffix).empty().append('Very High');
                    $('#curcon-'+area.suffix).empty().append('Use caution, limit exposure to the sun and use an SPF 30 moisturiser.');
                } else if (uvindex <= 20.0) {
                    $('#risk-'+area.suffix).empty().append('Extreme');
                    $('#curcon-'+area.suffix).empty().append('Use extreme caution, avoid exposure to the sun and use an SPF 30 moisturiser.');
                } else {
                    $('#risk-'+area.suffix).empty().append('Unavailable');
                    $('#curcon-'+area.suffix).empty().append('Information is currently unavailable.');
                }
    
            });
                });
    
            // END OF AUSTRALIAN UV FUNCTION
    
        });
    }
    

    and for the weather

    function getWeather() {
    
            // BEGIN AUSTRALIA and NEW ZEALAND WEATHER FUNCTION
                $(areas).each(function(){
                    var area = this;
            $.get('http://api.wxbug.net/getLiveCompactWeatherRSS.aspx?ACode=XXXPRIVATEXXX&stationid='+area.stationid+'&unittype=1&outputtype=1', function(d){
            $(d).find('weather').each(function(){
    
                var $weatherinfo = $(this); 
                var degrees = $weatherinfo.find('temp').text().replace(/\.0$/i, "");
                var conditions = $weatherinfo.find('current-condition').text();
                var icon = $weatherinfo.find('current-condition').attr('icon').replace(/\.gif$/i, ".png").split('http://deskwx.weatherbug.com/')[1];
    
                var temperature = temperature += '<span>' + degrees + '</span>' ;   
                $('#temp-'+area.suffix).empty().append($(temperature));
    
                var winformation = winformation += '<span>' + conditions + '</span>' ;
                $('#info-'+area.suffix).empty().append($(winformation));
    
                var wicon = wicon += '<img src="' + icon + '" alt="Weather Unavailable" />' ;
                $('#icon-'+area.suffix).empty().append($(wicon));
    
            });
            });
                });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.