0

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.

4
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by emclondon
1

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

1

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() ).

0

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

Edited by emclondon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.