This might be a very simple answer but it's been stumping me.

I need to load an xml file so Ican parse in in javascript. But the file is located on a different server entirely. Can I download it to disc with javascript, so I can load it later?

Thanks for any help.

you can use your brouwser to download the xml maualy
or
for automatic download you need to write a server site script (php-curl)

Hi,

You can try with Ajax. If it cannot get the xml directly, you can use an ajax function to access a php file on your server, that gets and returns the xml (using cUrl, or file_get_contents() ).

How would I use the PHP method?

either

<?php
    $feed_url = “http://www.engadget.com/rss.xml”;
    $data = file_get_contents($feed_url);
?>

get more info about that method here.
or

<?php

    function getData($feed_url) {

        $curl_handle = curl_init();

        curl_setopt ($curl_handle, CURLOPT_URL,$feed_url);
        curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl_handle);
        curl_close($curl_handle);

        return $result;
    }

    var_dump(getData("http://www.engadget.com/rss.xml"));
?>

Get more info about cURL here and here.

Further reading on which is best : http://stackoverflow.com/questions/555523/file-get-contents-vs-curl-what-has-better-performance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.