AS3由子值删除子节点的XML [英] AS3 Delete child node from XML by child value

查看:152
本文介绍了AS3由子值删除子节点的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与类似如下结构的XML;

I've got an XML with a structure like the following;

 <items>
    <item>5</item>
    <item>3006</item>
    <item>25</item>
    <item>458</item>
    <item>15</item>
    <item>78</item>
 </items>

我如何删除的项目,其值为458只是为了澄清这一点,我不知道该项目的指标,所以只是要求删除项目[索引]将不会在这里做。 我得值删除。

How do I delete the item with the value 458. Just to clarify this, I don't know the index of that item, so simply calling delete items[index] won't do here. I have to delete by value.

任何提示?

推荐答案

使用E4X过滤和使用过滤器里面的功能,你可以删除你想要的节点的可能性:

Using e4x filtering and the possibilities of using function inside the filter you can delete the node you want :

  • xml.item。(文()==值)会给你你正在寻找的节点
  • 的valueOf()会给你的当前节点你过滤
  • 删除将删除节点

所以结合这些相关信息,你可以这样做:

so combining these infos you can do :

var xml:XML=<items>
    <item>5</item>
    <item>3006</item>
    <item>25</item>
    <item>458</item>
    <item>15</item>
    <item>78</item>
 </items>;

 function deleteValue(xml:XML, value:String):void{
   xml.item.((text()==value) && (delete parent().children()[valueOf().childIndex()]));
 }

 deleteValue(xml, "458");

 trace(xml.toXMLString());

这篇关于AS3由子值删除子节点的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆