ActionScript - 使用 Array.sortOn() 对 XML 文件进行排序?

发布于 2024-10-01 17:48:50 字数 159 浏览 6 评论 0原文

我需要对一个大的 XML 文件进行排序,并且我一直在阅读将每个元素放入数组中是使用 Array 的 sortOn() 方法对数据进行排序的方法。

我担心速度。也许将它们存储到 Vector 中。 XML>代替数组是否会稍微提高速度,但这种方法是对 XML 数据进行排序的最佳方法吗?

i need to sort a large XML file and i've been reading that placing each of the elements into an array is the way to sort the data using Array's sortOn() method.

i'm concerned about speed. perhaps storing them into a Vector.< XML > instead of an Array will offer a slight increase in speed, or not, but is this approach the best way to sort XML data?

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

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

发布评论

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

评论(3

枯叶蝶 2024-10-08 17:48:50

实际上,我看到两种解决方案:

1/您加载静态 xml 文件,因此您可以手动进行排序。

2/ 您加载动态 xml 并为了提高速度,服务器端可以提供排序(在 PHP 中很容易)。
我认为这是更好的做法。

因此,在这两种情况下,您必须解析一次 xml,存储数据(向量、值对象)并通过销毁对 xml 的引用来清除内存。

如果你想在 Flash 端排序,你必须创建自己的函数,并且使用 sortOn 方法似乎是不可避免的。

Actually, I see two solutions :

1/ You load a static xml file and therefore you can do sorting manually.

2/ You load a dynamic xml and to gain speed, server side can provide sorting (easily in PHP).
i think this is the better thing to do.

So in the two case, you have to parse your xml once, store data (Vector, Value Object) and clear the memory by destroying the reference to your xml.

If you want to sort on Flash side, you have to create your own function and using the method sortOn seems inevitable.

一百个冬季 2024-10-08 17:48:50

@TheDarklnl1978 以下是 fl.data.DataProvider 的部分源代码,用于转换数组中的 XML(位于 Flash CS5 安装目录中):

var xml:XML = obj as XML;
retArr = [];
var nodes:XMLList = xml.*;
for each (var node:XML in nodes) {
    var obj:Object = {};
    var attrs:XMLList = node.attributes();
    for each (var attr:XML in attrs) {
        obj[attr.localName()] = attr.toString();
    }
    var propNodes:XMLList = node.*;
for each (var propNode:XML in propNodes) {
        if (propNode.hasSimpleContent()) {
            obj[propNode.localName()] = propNode.toString();
        }
    }
    retArr.push(obj);
}
return retArr;

@TheDarklnl1978 Here is part of the source code from fl.data.DataProvider that transform an XML in an Array (found in Flash CS5 install directory):

var xml:XML = obj as XML;
retArr = [];
var nodes:XMLList = xml.*;
for each (var node:XML in nodes) {
    var obj:Object = {};
    var attrs:XMLList = node.attributes();
    for each (var attr:XML in attrs) {
        obj[attr.localName()] = attr.toString();
    }
    var propNodes:XMLList = node.*;
for each (var propNode:XML in propNodes) {
        if (propNode.hasSimpleContent()) {
            obj[propNode.localName()] = propNode.toString();
        }
    }
    retArr.push(obj);
}
return retArr;
随风而去 2024-10-08 17:48:50

因此,为了回答我自己的问题,我相信使用 XML 创建 DataProvider 对象是最好的解决方案。

将 XML 分配给 DataProvider 不需要设置和迭代循环,尽管幕后可能发生内部循环。我很想知道它是否有效,所以如果您知道,请发表评论。

此外,DataProvider 对象还支持排序、检索以及创建列表、数据网格等的灵活性。

so, to answer my own question, i believe that creating a DataProvider object with the XML is the best solution.

assigning the XML to the DataProvider doesn't require setting up and iterating thru a loop, although there may be an internal loop happening behind the scenes. i would be interested to know if it does or not, so please leave a comment if you know.

additionally, DataProvider objects also support sorting, retrieval and flexibility for the creation of lists, data grids, etc.

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