0

So I'm starting this thread to fix a (likely syntax) error I encountered while implementing the answer by steven.yang at this question.

I tried his suggestion here, but got the error:

Unterminated regular expression literal.

This looks like a minor thing to fix, but I myself am not sure how to fix it.

Thanks!

update

since using jsonp makes it access the xml file, would it be possible to tell the computer to ignore any errors, just return the content of the <webcite_url> tags?

Community
  • 1
  • 1

2 Answers2

1

This php script will copy an external xml file to your local server. This will then allow you to parse that file instead.

I'm just working on a project that involves working with external data- you'll just need to execute this script when you want to update the xml file.

<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL, 'http://*path/to/external.xml*');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ($ch);
curl_close ($ch);
if (@simplexml_load_string($xml)) {
    /**
    * Create a new file
    */
    $fp = fopen('*desiredfilename*.xml', 'w');
    fwrite($fp, $xml);
    fclose($fp);
}

?>
keyser
  • 18,829
  • 16
  • 59
  • 101
0

The URL you're requesting isn't JSONP.

You get a syntax error when the browser tries to parse the XML response as Javascript.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • or rather, it doesn't have to parse it as anything. I just need to be able to retrieve the content between the `` tags, so if it can parse it as a string, that'd be fine. – Anthony Newman Feb 20 '12 at 04:41
  • 1
    @AnthonyNewman: No; you cannot circumvent the same-origin policy. You need server-side code. – SLaks Feb 20 '12 at 04:49
  • ah that again.... but seriously, in my original code with that regex error that pointed to the xml file I was looking for, it clearly accessed that file, so are you sure? – Anthony Newman Feb 20 '12 at 04:52
  • No; it can't be accessed. You can execute it as Javascript, but _you cannot read arbitrary content from another domain_. Period. – SLaks Feb 20 '12 at 05:28