1

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.

I'll appreciate any feedback.

2 Answers 2

5

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>

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>

Basically this line delete the node that matches with the number as i want (in this case, 1234):

delete myXML.employee.(elements('Compare') == '1234')[0];

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

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Gaston. It runs like a charm but I'm new to XML so I don't know how to implement it within Flash. It´s possible to see the FLA? Thanks!
@Sergio, you're welcome. I created this example in flash builder 4.6, this is a flex project, with this ide i can compile and deploy the actionscript code into swf file. For create a fla project I suppose that you must use flash cs. If you want, i can upload the project that you see in the link that i sent you.
thanks a lot. I'll try to adapt it to Flash CS5. Anyway, I'd like to review the example files. Cheers
@Sergio I edited the post, i uploaded the project file, please follow the instructions that I posted.
Many thanks. I'll download FBuilder and study your project. There are Flash Builder 4.7 and Flash Builder for PHP. What one I must download? It sounds obvious to me that the "PHP" version will do for both, XML and PHP projects. I'm right?
|
-2

Convert to an internal class, create a populate( data:XML ) and toXML():XML method. You will most likely have other methods in there.

2 Comments

Although the above answer satisfies our need, I believe mine comes from personal experience of working with Value Objects that come as XML. Thus I believe in the long run its more useful. Also, consider switching to JSON. AS3 has a native JSON parser.
I'll check JSON. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.