为什么我收到“无效的 XML”信息?在 Node.js 中调用 jQuery.parseXML 时?

发布于 2024-12-26 15:53:26 字数 363 浏览 4 评论 0原文

当我这样做时:

require('jquery').parseXML('<foo>bar</foo>');

我得到:

Invalid XML: <foo>bar</foo>

在浏览器中调用等效项 ($.parseXML('bar')) 似乎工作正常。我做错了什么?

我正在使用通过 NPM 安装的 Node.js v0.6.6 和 jquery v1.6.3。

如果有更合适的方法在 Node.js 中将字符串解析为 XML 文档,我也有兴趣学习。

When I do this:

require('jquery').parseXML('<foo>bar</foo>');

I get this:

Invalid XML: <foo>bar</foo>

Calling the equivalent in the browser ($.parseXML('<foo>bar</foo>')) seems to work fine. What am I doing wrong?

I am using Node.js v0.6.6 and jquery v1.6.3 installed via NPM.

If there is a more appropriate way to parse a string into an XML document in Node.js, I would be interested in learning that as well.

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

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

发布评论

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

评论(1

猛虎独行 2025-01-02 15:53:26

如果你想将其转换为 javascript 对象,你可以尝试 node-xml2js

You can try node-xml2js if you want to have it converted to javascript object.

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