如何在 javascript 中解析 XML 文件。大文件可能使用SAX?

发布于 2024-11-08 11:29:25 字数 1245 浏览 0 评论 0原文

大家好,

我正在拔头发,头痛,眼睛受伤。我曾到过这里和那里,但我似乎已经到了那里。

这将是我第一次使用 xml,并且真的很想让它发挥作用。这是一个大文件。我的眼睛很大+-5mb。我无法想象这个文件会被加载到内存中进行处理。用户会对此感到有点恼火。

基本上我们使用第三方网站来进行电子商务。因此,除了通过管理区域之外,我们无法访问数据库。

我们想要做的是确保地址方面没有任何问题。因此,我们得到了这个 xml 文件,其中列出了所有带有地区和州的邮政编码:

<?xml version="1.0"?>
<POSTCODES>
    <PostCode id="2035">
        <Area>2035 1</Area>
        <Area>2035 2</Area>
        <Area>2035 3</Area>
        <State>NSW</State>
    </Postcode>
    <PostCode id="2038">
        <Area>2038 1</Area>
        <Area>2038 2</Area>
        <Area>2038 3</Area>
        <State>NSW</State>
    </Postcode>
    <PostCode id="2111">
        <Area>2111 1</Area>
        <Area>2111 2</Area>
        <Area>2111 3</Area>
        <State>NSW</State>
    </Postcode>
</POSTCODES>

有人建议 SAX,但当被问及如何时突然死掉了?除非我没有正确查看,否则网络没有帮助。我看到很多例子。它们要么不展示如何读取文件,而是从文本区域中读取文件,要么示例是用 java 编写的。

我们想要什么?用户输入邮政编码 2038。我们希望使用该数据转到 javascript,并向我们返回该邮政编码内的所有郊区。

有人可以告诉我要下载什么以及如何使用它来获得我需要的东西吗?

拜托,拜托,拜托。很难看到一个成年男子乞讨和哭泣,但我确实如此。

G'day All,

I am pulling my hair out, getting headaches and my eyes hurt. I have been hither and thither and I seem to get whither.

This will be my first experience with xml and would really want to get this working. It is a large file. Well large in my eyes +-5mb. I can not imagine that this file would be loaded into memory to process. Users will get a bit peeved with this.

Basically we are using a 3rd parties site to do our ecommerce. So we have no access to the database other than via the admin area.

What we want to do is make sure that there is no stuff ups when it comes to addresses. Therefore we got this xml file put together listing all postcodes with areas and states:

<?xml version="1.0"?>
<POSTCODES>
    <PostCode id="2035">
        <Area>2035 1</Area>
        <Area>2035 2</Area>
        <Area>2035 3</Area>
        <State>NSW</State>
    </Postcode>
    <PostCode id="2038">
        <Area>2038 1</Area>
        <Area>2038 2</Area>
        <Area>2038 3</Area>
        <State>NSW</State>
    </Postcode>
    <PostCode id="2111">
        <Area>2111 1</Area>
        <Area>2111 2</Area>
        <Area>2111 3</Area>
        <State>NSW</State>
    </Postcode>
</POSTCODES>

Someone suggested SAX but suddenly died when asked how? The web is not helping unless I am not looking properly. I see a lot of examples. Either they do not show how to read the file but rather do it from a textarea or the example is in java.

What do we want? User enters a post code of 2038. We want to go to the javascript with that data and have returned to us all the suburbs that full within that post code.

Anyone out there that can please tell me what to download and how to use it to get what i need?

Please, please, please. It is hard to see a grown man begging and crying but I am.

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

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

发布评论

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

评论(2

盗心人 2024-11-15 11:29:25

听起来您想要在服务器上有一个脚本,该脚本将根据用户的邮政编码选择来建议郊区?您可以使用 jQuery 的 ajax 功能来执行此操作。

您也许还可以使用 jQueryUI 的自动完成控件来解析 XML 并提出建议: http://jqueryui.com /demos/autocomplete/#xml

也可以完全用 javascript 来完成此操作,而无需服务器端任何脚本,但如果 XML 文件为 5MB,则加载速度会相当慢。您可以在从服务器传输之前通过 gzip 压缩文件,从而显着减小文件大小。

Sounds like you want a script on the server which will suggest suburbs based on the users postcode selection? You could use jQuery's ajax functionality to do this.

You might also be able to use jQueryUI's autocomplete control to parse XML and make suggestions: http://jqueryui.com/demos/autocomplete/#xml

It's also possible to do this entirely in javascript without any script on the server side, but it would be pretty slow at loading if the XML file is 5MB. You might be able to get a significant reduction in file size thought by gzipping it before transmission from the server.

糖粟与秋泊 2024-11-15 11:29:25

如果您需要在 Javascript 中解析它,您可以使用 jQuery。
http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery

If you need to parse this in Javascript, you can use jQuery.
http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery

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