E4X 中的过滤
这只是一个简单的问题。我目前正在使用 Mozilla 的 Rhino 开发一个小型网络应用程序。第一步,我需要获取一个网页并过滤它的所有节点。为此,我使用 E4X。我以为我可以这样做:
var pnodes = doc..*(p);
但这会产生错误。怎样做才是正确的?
(顺便说一句:这只是提高性能的一个步骤。代码已经做得很好,只是有点慢。)
This is just a simple question. I'm currently using Mozilla's Rhino to develop a little webapp. As one step, I need to get a webpage and filter all of it's nodes. For doing that, I use E4X. I thought I could do this like that:
var pnodes = doc..*(p);
But that produces an error. How is it done right?
(BTW: this is just a step for increasing performance. The code already does well, it's just a bit slow.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用以下内容:
请注意,这里有一个 bug在 Rhino 和 SpiderMonkey 实现中,过滤器表达式
name() == "p"
的范围没有正确限定到当前节点,因此XML
或都没有定义了 XMLList
方法。另一个可行的解决方案是查找文档中的所有
p
节点并将每个节点的父节点累积到一个数组中。You should be able to use the following:
Note that this there is a bug in the Rhino and SpiderMonkey implementations where the filter expression
name() == "p"
is not correctly scoped to the current node, so none of theXML
orXMLList
methods are defined.Another workable solution is to lookup all
p
nodes in the document and accumulate the parent of each in an array.