也许下面的代码会有用。假设 xml 结构将是这样的:
<dbase>
<employee>
<Name>NAME</Name>
<Surname>SURNAME</Surname>
<Company>COMPANY</Company>
<Date>DATE</Date>
<Compare>1377390433625</Compare>
</employee>
<employee>
<Name>WILL BE DELETED</Name>
<Surname>SURNAME</Surname>
<Company>COMPANY</Company>
<Date>DATE</Date>
<Compare>1234</Compare>
</employee>
<employee>
<Name>NAME</Name>
<Surname>SURNAME</Surname>
<Company>COMPANY</Company>
<Date>DATE</Date>
<Compare>34878937</Compare>
</employee>
</dbase>
在接下来的代码中,我将删除节点Compare = 1234
:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
<mx:Script>
<![CDATA[
public function init():void{
delete myXML.employee.(elements('Compare') == '1234')[0];
txt.text = myXML.toString();
}
]]>
</mx:Script>
<mx:XML id="myXML">
<dbase>
<employee>
<Name>NAME</Name>
<Surname>SURNAME</Surname>
<Company>COMPANY</Company>
<Date>DATE</Date>
<Compare>1377390433625</Compare>
</employee>
<employee>
<Name>WILL BE DELETED</Name>
<Surname>SURNAME</Surname>
<Company>COMPANY</Company>
<Date>DATE</Date>
<Compare>1234</Compare>
</employee>
<employee>
<Name>NAME</Name>
<Surname>SURNAME</Surname>
<Company>COMPANY</Company>
<Date>DATE</Date>
<Compare>34878937</Compare>
</employee>
</dbase>
</mx:XML>
<mx:TextArea id="txt" width="400" height="400" />
</mx:Application>
基本上,这一行删除了与我想要的数字匹配的节点(在本例中为1234):
delete myXML.employee.(elements('Compare') == '1234')[0];
你可以在这里试试这个链接。我希望这会有用。
(已编辑)2013-08-26:这里是下载项目的链接。这个文件是一个.fxp文件,你可以导入这个,点击File --> Import... --> Flash Builder Project.. -->选择.fxp文件。