AS3由子值删除子节点的XML节点、XML

2023-09-09 21:47:41 作者:恋上你每天缠着我

我有与类似如下结构的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());
 
精彩推荐
图片推荐