AS3 XML删除节点 [英] AS3 XML delete node

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

问题描述

我有这样的XML结构:

I have this XML structure:

<dbase>
   <employee>
      <Name>NAME</Name>
      <Surname>SURNAME</Surname>
      <Company>COMPANY</Company>
      <Date>DATE</Date>
      <Compare>1377390433625</Compare>
   </employee>
</dbase>

我想知道如何寻找的比较值的删除员工如果有匹配。

I'd like to know how to search for the Compare value an delete the employee if there is a match.

我会AP preciate任何反馈。

I'll appreciate any feedback.

推荐答案

也许下面的code将是有益的。假设XML结构是这样的:

Maybe the following code will be useful. Assuming that the xml structure will be like this:

        <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>

在接下来的code,我会删除与节点比较= 1234

In the next code, i will delete the node with 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];

您可以试试这个这里的 LINK 。 我希望这将是有益的。

You can try this here LINK. I hope this will be useful.

(编辑)2013年8月26日: 这里的 LINK 下载项目。这个文件是一个.fxp文件,你可以导入此,点击文件 - > 导入... - > Flash Builder项目.. - > 选择.fxp文件

(Edited) 2013-08-26: Here the LINK for download the project. This file is a .fxp file, you can import this, click in File --> Import... --> Flash Builder Project.. --> select the .fxp file.

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

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