Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-02-2007, 09:32 PM   #1
Sleeve
Corrupted Whitespace
 
Join Date: May 2006
Location: Seattle, WA
Posts: 489
Default Deleting XML Element

Can't really find anything on this and I'm having a heck of a time.

I thought I could delete an element by passing a XML reference to the delete(XML) method.
ActionScript Code:
var xml : XML = new XML(<column>     <row type='header' font='Verdana' size='10'>Title</row>     <row font='Verdana' size='12'>item1</row>     <row font='Verdana' size='10'>item2</row> </column>)
then delete it using this
ActionScript Code:
var ref : XML = <row font='Verdana' size='12'>item1</row>; delete (xml.ref);

Any help on this?
__________________
Some people smoke, some drink...I code Actionscript
Sleeve is offline   Reply With Quote
Old 08-02-2007, 09:42 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,784
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

xml.ref finds the ref nodes in the xml. Instead what you can do is use

ActionScript Code:
delete xml.row[1];
__________________
(6)
senocular is offline   Reply With Quote
Old 08-02-2007, 09:50 PM   #3
Sleeve
Corrupted Whitespace
 
Join Date: May 2006
Location: Seattle, WA
Posts: 489
Default

Yes however, the XML data is dynamically created and it may not be possible to know the element number. I could iterate through the XML object, convert each element to an XML string and compare it to 'ref' but I had hoped I could avoid this.

Looks like I'll have to find some other way.
__________________
Some people smoke, some drink...I code Actionscript
Sleeve is offline   Reply With Quote
Old 08-02-2007, 10:00 PM   #4
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,784
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

if all you have is the string representation of the node to be deleted, that might be the only way.
__________________
(6)
senocular is offline   Reply With Quote
Old 08-02-2007, 10:24 PM   #5
Sleeve
Corrupted Whitespace
 
Join Date: May 2006
Location: Seattle, WA
Posts: 489
Default

So, maybe you can provide some clarity on how to delete an XML node by passing an XMLList reference as the operand.

I keep getting this error: TypeError: Error #1119: Delete operator is not supported with operand of type XMLList. Yet in the documentation, it states "When used with an XMLList operand, the result of the delete operator is always true because the XMLList operand always refers to a valid (though possibly empty) XMLList object."
__________________
Some people smoke, some drink...I code Actionscript
Sleeve is offline   Reply With Quote
Old 08-04-2007, 12:53 AM   #6
Jim Freer
Senior Member
 
Join Date: Jul 2007
Location: Houston, TX
Posts: 355
Send a message via Yahoo to Jim Freer
Default

This will delete the row for you. I would have to see more code to know how you got the target row as an XMLList.

Code:
deleteColumnRow( <row font='Verdana' size='12'>item1</row> );
Code:
private function deleteColumnRow
    ( avXml:XML )
    :void
{
    for( var lvIndex:int = 0; lvIndex < xml.row.length(); lvIndex++ )
    {
        if( xml.row[lvIndex] == avXml )
        {
            delete xml.row[lvIndex]
            break;
        } // if
    } // for each
    
} // deleteColumnRow
http://freerpad.blogspot.com/
Jim Freer is offline   Reply With Quote
Old 10-14-2007, 06:05 AM   #7
Roustalski
Registered User
 
Join Date: Aug 2007
Posts: 11
Default

Quote:
Originally Posted by Sleeve View Post
Can't really find anything on this and I'm having a heck of a time.

I thought I could delete an element by passing a XML reference to the delete(XML) method.
ActionScript Code:
var xml : XML = new XML(<column>     <row type='header' font='Verdana' size='10'>Title</row>     <row font='Verdana' size='12'>item1</row>     <row font='Verdana' size='10'>item2</row> </column>)
then delete it using this
ActionScript Code:
var ref : XML = <row font='Verdana' size='12'>item1</row>; delete (xml.ref);

Any help on this?
delete xml.row.(@size == "12")[0];

Simply add "[0]" to the end of the where clause if you are narrowing down the list to one element. Although in this case, I don't know if the 12 is a good unique identifier, but I think you get the idea.
Roustalski is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML scope question X-Fe@R ActionScript 2.0 1 07-19-2007 11:12 AM
deleting xml entry with php damiro Server-Side Scripting 3 06-06-2007 08:31 AM
xml preloading problems irish10945 ActionScript 2.0 3 04-02-2007 05:00 PM
releasing xml file from XML.onLoad() sophistikat ActionScript 2.0 2 02-21-2007 07:00 PM
Deleting an element from an array compuboy1010 ActionScript 2.0 3 09-29-2005 10:58 AM


All times are GMT. The time now is 07:54 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.