我有与类似如下结构的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());