<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Deleting XML nodes: harder than it looks</title>
	<atom:link href="http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/feed/" rel="self" type="application/rss+xml" />
	<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/</link>
	<description>Developing ActionScript applications from the command line</description>
	<lastBuildDate>Fri, 18 Dec 2009 21:24:18 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Vic Mortelmans</title>
		<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/#comment-128</link>
		<dc:creator>Vic Mortelmans</dc:creator>
		<pubDate>Fri, 18 Dec 2009 21:24:18 +0000</pubDate>
		<guid isPermaLink="false">http://bottomupflash.wordpress.com/?p=29#comment-128</guid>
		<description>So if I want to delete all elements that match some xpath, this is the only (clumsy) way to go?:

var nrofitemstodelete = queryoutput..div.(@[&quot;class&quot;] == &#039;opomba-layer&#039;).length();
for (i=0;i&lt;nrofitemstodelete;i++) {
	delete queryoutput..div.(@[&quot;class&quot;] == &#039;opomba-layer&#039;)[0];
}


Seems like a performance penalty, since the xpath is evaluated over and over.

Can one evaluate the delete, to see if it actually deleted an item? Then a while-loop would be more appropriate.

Groeten,
Vic</description>
		<content:encoded><![CDATA[<p>So if I want to delete all elements that match some xpath, this is the only (clumsy) way to go?:</p>
<p>var nrofitemstodelete = queryoutput..div.(@["class"] == &#8216;opomba-layer&#8217;).length();<br />
for (i=0;i&lt;nrofitemstodelete;i++) {<br />
	delete queryoutput..div.(@[&quot;class&quot;] == &#039;opomba-layer&#039;)[0];<br />
}</p>
<p>Seems like a performance penalty, since the xpath is evaluated over and over.</p>
<p>Can one evaluate the delete, to see if it actually deleted an item? Then a while-loop would be more appropriate.</p>
<p>Groeten,<br />
Vic</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liza</title>
		<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/#comment-40</link>
		<dc:creator>Liza</dc:creator>
		<pubDate>Fri, 24 Apr 2009 11:19:37 +0000</pubDate>
		<guid isPermaLink="false">http://bottomupflash.wordpress.com/?p=29#comment-40</guid>
		<description>If you ever want to hear a reader&#039;s feedback :) , I rate this post for four from five. Decent info, but I just have to go to that damn msn to find the missed bits. Thanks, anyway!</description>
		<content:encoded><![CDATA[<p>If you ever want to hear a reader&#8217;s feedback :) , I rate this post for four from five. Decent info, but I just have to go to that damn msn to find the missed bits. Thanks, anyway!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brio1337</title>
		<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/#comment-34</link>
		<dc:creator>brio1337</dc:creator>
		<pubDate>Tue, 24 Feb 2009 22:37:43 +0000</pubDate>
		<guid isPermaLink="false">http://bottomupflash.wordpress.com/?p=29#comment-34</guid>
		<description>kanenas, I agree, that&#039;s the exact same piece of code I just determined for deleting a known XML node from its parent.

quinthar, thanks for your article, I agree that deleting XML nodes is harder than it looks! Part of the reason is that Adobe doesn&#039;t explain very well how these XML and XMLList objects are related. I see some wording in your article that indicates a misunderstanding.
When you discuss child.appendChild(grandChild), you say that you expected it to return a reference to the node it just &quot;allocated&quot;. But there is no node allocated: grandChild is changed to be part of child&#039;s tree. So now grandChild&#039;s parent() and childIndex() are now valid. This has some consequences, such as you can&#039;t take a node and append it to several other XML nodes and expect it to be in all of them. (You can use the XML object&#039;s copy() function for that).

Similarly, when you call children() on an XML object, the XMLList returned is a reference to the actual child list inside the XML object. So if you delete a node from this list, you&#039;ve actually deleted it from the parent!

I wish Adobe was clearer about this stuff...</description>
		<content:encoded><![CDATA[<p>kanenas, I agree, that&#8217;s the exact same piece of code I just determined for deleting a known XML node from its parent.</p>
<p>quinthar, thanks for your article, I agree that deleting XML nodes is harder than it looks! Part of the reason is that Adobe doesn&#8217;t explain very well how these XML and XMLList objects are related. I see some wording in your article that indicates a misunderstanding.<br />
When you discuss child.appendChild(grandChild), you say that you expected it to return a reference to the node it just &#8220;allocated&#8221;. But there is no node allocated: grandChild is changed to be part of child&#8217;s tree. So now grandChild&#8217;s parent() and childIndex() are now valid. This has some consequences, such as you can&#8217;t take a node and append it to several other XML nodes and expect it to be in all of them. (You can use the XML object&#8217;s copy() function for that).</p>
<p>Similarly, when you call children() on an XML object, the XMLList returned is a reference to the actual child list inside the XML object. So if you delete a node from this list, you&#8217;ve actually deleted it from the parent!</p>
<p>I wish Adobe was clearer about this stuff&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kanenas</title>
		<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/#comment-27</link>
		<dc:creator>kanenas</dc:creator>
		<pubDate>Thu, 22 Jan 2009 14:04:16 +0000</pubDate>
		<guid isPermaLink="false">http://bottomupflash.wordpress.com/?p=29#comment-27</guid>
		<description>The &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/operators.html#delete_(XML)&quot; rel=&quot;nofollow&quot;&gt;delete&lt;/a&gt; operator is indeed the official way (as mentioned in the &quot;&lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/XML.html#appendChild()&quot; rel=&quot;nofollow&quot;&gt;appendChild()&lt;/a&gt;&quot; documentation) to remove a child node. Perhaps the &quot;Attempt to delete the fixed property...&quot; error arises because grandChild is not the result of an E4X expression?  Whatever the cause, you can get a child node&#039;s index with the &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/XML.html#childIndex()&quot; rel=&quot;nofollow&quot;&gt;childIndex()&lt;/a&gt; method:

&lt;code&gt;delete grandChild.parent().children()[grandChild.childIndex()]&lt;/code&gt;

A bit lengthy, .</description>
		<content:encoded><![CDATA[<p>The <a href="http://livedocs.adobe.com/flex/3/langref/operators.html#delete_(XML)" rel="nofollow">delete</a> operator is indeed the official way (as mentioned in the &#8220;<a href="http://livedocs.adobe.com/flex/3/langref/XML.html#appendChild()" rel="nofollow">appendChild()</a>&#8221; documentation) to remove a child node. Perhaps the &#8220;Attempt to delete the fixed property&#8230;&#8221; error arises because grandChild is not the result of an E4X expression?  Whatever the cause, you can get a child node&#8217;s index with the <a href="http://livedocs.adobe.com/flex/3/langref/XML.html#childIndex()" rel="nofollow">childIndex()</a> method:</p>
<p><code>delete grandChild.parent().children()[grandChild.childIndex()]</code></p>
<p>A bit lengthy, .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: noah a-b</title>
		<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/#comment-26</link>
		<dc:creator>noah a-b</dc:creator>
		<pubDate>Mon, 24 Nov 2008 21:55:21 +0000</pubDate>
		<guid isPermaLink="false">http://bottomupflash.wordpress.com/?p=29#comment-26</guid>
		<description>Wow! They can make things so darn tricky it&#039;s, like searching for a needle in a haystack, only the needle could also randomly be disguised as either a thumbtack, a bobby pin, a screw, or a paperclip!

Your post helped me a lot, but I must say it was this little nugget that finally solved my node deletion issue!

&quot;... you have to use the [0] index or the delete function will puke.&quot;

Praise the code demons!</description>
		<content:encoded><![CDATA[<p>Wow! They can make things so darn tricky it&#8217;s, like searching for a needle in a haystack, only the needle could also randomly be disguised as either a thumbtack, a bobby pin, a screw, or a paperclip!</p>
<p>Your post helped me a lot, but I must say it was this little nugget that finally solved my node deletion issue!</p>
<p>&#8220;&#8230; you have to use the [0] index or the delete function will puke.&#8221;</p>
<p>Praise the code demons!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://bottomupflash.wordpress.com/2008/03/26/deleting-xml-nodes-harder-than-it-looks/#comment-25</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Tue, 21 Oct 2008 02:26:53 +0000</pubDate>
		<guid isPermaLink="false">http://bottomupflash.wordpress.com/?p=29#comment-25</guid>
		<description>This post didn&#039;t solve my problem directly, but you got me headed in the right direction so I thought I&#039;d share the solution.

I needed to remove an arbitrary node at an arbitrary depth in an XML object. The solution is in two parts.

First, each element that will be deleted needs a UID so I used the UIDUtil.createUID(); function.

var xDoc:XML = XML(&#039;&#039;);

I get the item to delete from a Tree.selectedItem call

var delItem:XML = XML(Tree.selectedItem);

Then the delete command is:

delete xDoc.descendants().(@uid==delItem.@uid)[0];

That searches recursively for all elements that have a uid parameter and matches them to the selected item&#039;s uid. Since the return value is an XMLList (even if only 1 item is returned) you have to use the [0] index or the delete function will puke.

Enjoy :)</description>
		<content:encoded><![CDATA[<p>This post didn&#8217;t solve my problem directly, but you got me headed in the right direction so I thought I&#8217;d share the solution.</p>
<p>I needed to remove an arbitrary node at an arbitrary depth in an XML object. The solution is in two parts.</p>
<p>First, each element that will be deleted needs a UID so I used the UIDUtil.createUID(); function.</p>
<p>var xDoc:XML = XML(&#8221;);</p>
<p>I get the item to delete from a Tree.selectedItem call</p>
<p>var delItem:XML = XML(Tree.selectedItem);</p>
<p>Then the delete command is:</p>
<p>delete xDoc.descendants().(@uid==delItem.@uid)[0];</p>
<p>That searches recursively for all elements that have a uid parameter and matches them to the selected item&#8217;s uid. Since the return value is an XMLList (even if only 1 item is returned) you have to use the [0] index or the delete function will puke.</p>
<p>Enjoy :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
