按文档顺序对 AS3 XMLList 进行排序
在 Actionscript 3 中,有没有一种方法可以按文档顺序对 XMLList 中的节点(XML 类型的实例)进行排序(如 XDM 规范; “通俗地说,文档顺序是节点在文档的 XML 序列化中出现的顺序”)?或者,有没有办法比较两个节点的文档位置?
这是我的意思的一个小例子。在实际情况中,列表是通过更加复杂的过程构建的,并且可能有数百个节点。
var x:XML = <a><b/><b/></a>;
var b0:XML = x.b[0];
var b1:XML = x.b[1];
var l:XMLList = new XMLList();
l += b1;
l += b0;
var sl:XMLList = documentSortFunction(l);
assertTrue(sl[0] === b0);
我不确定我在这里有很大的希望,因为 ECMA-357 (E4X) 似乎并没有真正的文档概念,更不用说文档顺序了。
In Actionscript 3, is there a way to sort the nodes (instances of type XML) in an XMLList in document order (as defined in the XDM spec; "Informally, document order is the order in which nodes appear in the XML serialization of a document")? Alternately, is there a way to compare the document position of two nodes?
Here's a little example of what I mean. In the real case, the list is constructed by a much more complicated process and might have hundreds of nodes.
var x:XML = <a><b/><b/></a>;
var b0:XML = x.b[0];
var b1:XML = x.b[1];
var l:XMLList = new XMLList();
l += b1;
l += b0;
var sl:XMLList = documentSortFunction(l);
assertTrue(sl[0] === b0);
I'm not sure I have a lot of hope here, since it seems that ECMA-357 (E4X) doesn't really have a concept of document, much less document order.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这是我得出的答案的草图。这还没有经过太多测试,但我想我应该在忘记之前记录下来。
这个想法是实现一个函数来为节点生成字符串,使得字符串的顺序与节点的顺序相同。
Well, here's a sketch of the answer I came up with. This hasn't been tested much yet, but I thought I'd record it before I forget to.
The idea is to implement a function to generate a string for a node, such that the order of the strings is the same as the order of the nodes.