“未终止的正则表达式文字”通过 javaScript 解析来自外部域的 XML 数据时出错

发布于 2025-01-07 00:01:52 字数 478 浏览 3 评论 0原文

因此,我开始这个线程来修复我在实现 steven.yang 的答案时遇到的(可能是语法)错误 这个问题

我尝试了他的建议此处,但收到错误:

未终止的正则表达式文字。

这看起来像是一个需要解决的小问题,但我自己不知道如何解决它。

谢谢!

update

由于使用 jsonp 会访问 xml 文件,是否可以告诉计算机忽略任何错误,只返回 标记的内容?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰つ倒转 2025-01-14 00:01:52

此 php 脚本会将外部 xml 文件复制到本地服务器。然后,这将允许您解析该文件。

我正在开发一个涉及使用外部数据的项目 - 当您想要更新 xml 文件时,您只需要执行此脚本。

<?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);
}

?>

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);
}

?>
用心笑 2025-01-14 00:01:52

您请求的 URL 不是 JSONP。

当浏览器尝试将 XML 响应解析为 Javascript 时,您会收到语法错误。

The URL you're requesting isn't JSONP.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文