使用“..”过滤 XMLList符号
有件事我无法解决:当我在包含多个层次结构的 XMLList 中搜索特定节点时,过滤器永远不会在顶级父节点中搜索。
例如,如果我有一棵这样的树:
<node id="a0KQ0000002PTN5MAO" parentId="">
<node id="a0KQ0000002PT8iMAG" parentId="a0KQ0000002PTN5MAO" />
</node>
如果我做了这样的研究:
var aNode = ac_hierarchy.source..node.(@id == "a0KQ0000002PTN5MAO")[0];
我将得不到结果,“aNode”将为空:/
任何想法吗?
[编辑] 还有一些我无法理解的事情(我正在搜索 2 天:/):
我使用以下方法递归地将节点添加到 ac_hierarchy 中:
private function add_item_to_hierarchy(node:Node_vo):XML {
var firstNode:XML = ac_hierarchy.getItemAt(0) as XML;
var parentNode:XML;
if (firstNode.@[Node_vo.att_id] == node.parentId)
parentNode = firstNode;
else
parentNode = ac_hierarchy.source..node.(@[Node_vo.att_id] == node.parentId)[0];
var test:XML = ac_hierarchy.source..node.(@[Node_vo.att_id] == node.parentId)[0];
var test2:XML = ac_hierarchy.source..node.(@[Node_vo.att_id] == "a0KQ0000002PT8iMAG")[0];
newXmlNode = node.toXML();
// Add the current node to his parent node
parentNode.appendChild(newXmlNode);
}
第一次使用“node.parentId”参数调用“add_item_to_hierarchy”等于“a0KQ0000002PTN5MAO”方法,ac_hierarchy 看起来像:
<node id="a0KQ0000002PTN5MAO" parentId="" />
var test:XML 已填充。
var test2:XML 未填充。
它正确地追加了Child。
第二次,“node.parentId”参数等于“a0KQ0000002PT8iMAG”,并且 ac_hierarchy 看起来像:
<node id="a0KQ0000002PTN5MAO" parentId="">
<node id="a0KQ0000002PT8iMAG" parentId="a0KQ0000002PTN5MAO"/>
</node>
var test:XML 已填充。
var test2:XML 已填充。
它还正确地追加了Child。
第三次,“node.parentId”参数再次等于“a0KQ0000002PT8iMAG”,并且 ac_hierarchy 看起来像:
<node id="a0KQ0000002PTN5MAO" parentId="">
<node id="a0KQ0000002PT8iMAG" parentId="a0KQ0000002PTN5MAO">
<node id="a0KQ0000002PTL9MAO"/>
</node>
</node>
var test:XML 未填充。
var test2:XML 已填充。
但这一次,var“test”为空(尽管“node.parentId”值与之前的循环相同并且test2被正确填充)!!!
我很快就会损坏我的电脑:/
感谢您的帮助。
There is something I couldn't solve: when I search a specific node in a XMLList containing several level of hierarchy, filter never search in the top parent node.
For example, if I have a tree like this:
<node id="a0KQ0000002PTN5MAO" parentId="">
<node id="a0KQ0000002PT8iMAG" parentId="a0KQ0000002PTN5MAO" />
</node>
and if I made a reseach like this:
var aNode = ac_hierarchy.source..node.(@id == "a0KQ0000002PTN5MAO")[0];
I will get no results, "aNode" will be null :/
Any idee ?
[EDIT]
There is something else I can't understand (and I'm searching for 2 days :/):
I recursively add nodes to the ac_hierarchy using the method bellow:
private function add_item_to_hierarchy(node:Node_vo):XML {
var firstNode:XML = ac_hierarchy.getItemAt(0) as XML;
var parentNode:XML;
if (firstNode.@[Node_vo.att_id] == node.parentId)
parentNode = firstNode;
else
parentNode = ac_hierarchy.source..node.(@[Node_vo.att_id] == node.parentId)[0];
var test:XML = ac_hierarchy.source..node.(@[Node_vo.att_id] == node.parentId)[0];
var test2:XML = ac_hierarchy.source..node.(@[Node_vo.att_id] == "a0KQ0000002PT8iMAG")[0];
newXmlNode = node.toXML();
// Add the current node to his parent node
parentNode.appendChild(newXmlNode);
}
The first time I call the "add_item_to_hierarchy" with "node.parentId" parameter equals to "a0KQ0000002PTN5MAO" method, ac_hierarchy looks like:
<node id="a0KQ0000002PTN5MAO" parentId="" />
var test:XML is filled.
var test2:XML is not filled.
It correctly appendChild.
The second time, "node.parentId" parameters equals to "a0KQ0000002PT8iMAG" and ac_hierarchy looks like:
<node id="a0KQ0000002PTN5MAO" parentId="">
<node id="a0KQ0000002PT8iMAG" parentId="a0KQ0000002PTN5MAO"/>
</node>
var test:XML is filled.
var test2:XML is filled.
It also correctly appendChild.
And the third time, "node.parentId" parameters again equals to "a0KQ0000002PT8iMAG" and ac_hierarchy looks like:
<node id="a0KQ0000002PTN5MAO" parentId="">
<node id="a0KQ0000002PT8iMAG" parentId="a0KQ0000002PTN5MAO">
<node id="a0KQ0000002PTL9MAO"/>
</node>
</node>
var test:XML is NOT filled.
var test2:XML is filled.
But this time, var "test" is null (although "node.parentId" value is the same as previous loop and test2 is correctly fill) !!!
I will soon break my computer :/
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,xml 选择器不会检查根节点,但有一些解决方法:
将父节点放入代理 XMLList 并搜索它:
var list:XMLList = new XMLList();
list[0] = <节点 id="1"/>;
var results:XMLList = list.(@id == "1");
或仅单独检查父节点并添加到搜索结果。
Yes, xml selectors don't check root node, but there are workarounds:
Get your parent node into proxy XMLList and search it:
var list:XMLList = new XMLList();
list[0] = <node id="1"/>;
var results:XMLList = list.(@id == "1");
or just check parent node separately and add to search results.