<?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/"
		>
<channel>
	<title>Comments on: ReferenceError: Error #1065 re: E4X XML search</title>
	<atom:link href="http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/</link>
	<description>eightdotthree.net is maintained for me to share, learn and experiment. Through monthly posting I hope to find my writing voice, develop as a designer and maybe provide something interesting. Hosting provided by Dreamhost.</description>
	<lastBuildDate>Wed, 30 Jun 2010 22:16:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Searching XML on attribute results in runtime error: Variable @ is not defined. &#171; Development scratchbook</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39989</link>
		<dc:creator>Searching XML on attribute results in runtime error: Variable @ is not defined. &#171; Development scratchbook</dc:creator>
		<pubDate>Sat, 30 Jan 2010 14:34:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39989</guid>
		<description>&lt;p&gt;[...] See this. [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] See this. [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: matthew</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39979</link>
		<dc:creator>matthew</dc:creator>
		<pubDate>Tue, 29 Dec 2009 15:55:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39979</guid>
		<description>&lt;p&gt;@jameser I think the reason that it can&#039;t &quot;return either the result or nothing at all,&quot; is a result of the implicit scope.  With node selection (like the example you gave), it&#039;s a simple lookup with an explicit scope—in your example, the scope is &lt;code&gt;xml.children()&lt;/code&gt;.  When using a filter to check an attribute value, however, the scope is implicit.  For example, consider &lt;code&gt;myXMLList.(@attr == &quot;value&quot;)&lt;/code&gt;.  Flash has to resolve the variable &lt;code&gt;@attr&lt;/code&gt; by climbing the scope chain.  But it&#039;s not defined on the XMLList (or anything else in the scope chain) so you get an error.  Still, this seems like desirable behavior in light of this example:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;
var myVar:Number = 5;
trace(myXMLList.(@attr == myVar));
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Clearly, the expectation is that the &lt;code&gt;myVar&lt;/code&gt; in the filter is the variable defined above, and that Flash will find the variable in the scope chain after &lt;em&gt;not finding it&lt;/em&gt; in the XMLList.  The same behavior must apply to &lt;code&gt;@attr&lt;/code&gt;, but since that doesn&#039;t exist anywhere in the scope chain, you&#039;ll get the error Ryan describes.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@jameser I think the reason that it can&#8217;t &#8220;return either the result or nothing at all,&#8221; is a result of the implicit scope.  With node selection (like the example you gave), it&#8217;s a simple lookup with an explicit scope—in your example, the scope is <code>xml.children()</code>.  When using a filter to check an attribute value, however, the scope is implicit.  For example, consider <code>myXMLList.(@attr == "value")</code>.  Flash has to resolve the variable <code>@attr</code> by climbing the scope chain.  But it&#8217;s not defined on the XMLList (or anything else in the scope chain) so you get an error.  Still, this seems like desirable behavior in light of this example:</p>

<p><pre><code>
var myVar:Number = 5;
trace(myXMLList.(@attr == myVar));
</code></pre></p>

<p>Clearly, the expectation is that the <code>myVar</code> in the filter is the variable defined above, and that Flash will find the variable in the scope chain after <em>not finding it</em> in the XMLList.  The same behavior must apply to <code>@attr</code>, but since that doesn&#8217;t exist anywhere in the scope chain, you&#8217;ll get the error Ryan describes.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39974</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Thu, 19 Nov 2009 14:06:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39974</guid>
		<description>&lt;p&gt;Glad to have helped!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Glad to have helped!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jamesr</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39973</link>
		<dc:creator>jamesr</dc:creator>
		<pubDate>Thu, 19 Nov 2009 12:47:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39973</guid>
		<description>&lt;p&gt;Actually, in response to mathews comment, if you run this code using describeType, even though all the nodes in the children don&#039;t contain an attribute called &#039;name&#039;, it still returns the values for those that do, without throwing any errors.&lt;/p&gt;

&lt;p&gt;var xml : XML = describeType( myClass );
var list : XMLList = xml.children()@name;&lt;/p&gt;

&lt;p&gt;trace( list );
trace( xml..@name );&lt;/p&gt;

&lt;p&gt;I realise that this isn&#039;t using filtering with expressions, but i&#039;d think it would go through a fairly similar process.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Actually, in response to mathews comment, if you run this code using describeType, even though all the nodes in the children don&#8217;t contain an attribute called &#8216;name&#8217;, it still returns the values for those that do, without throwing any errors.</p>

<p>var xml : XML = describeType( myClass );
var list : XMLList = xml.children()@name;</p>

<p>trace( list );
trace( xml..@name );</p>

<p>I realise that this isn&#8217;t using filtering with expressions, but i&#8217;d think it would go through a fairly similar process.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jamesr</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39972</link>
		<dc:creator>jamesr</dc:creator>
		<pubDate>Thu, 19 Nov 2009 12:30:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39972</guid>
		<description>&lt;p&gt;Cheers for this, you&#039;ve just stopped my small headache turning into  massive one. I understand what matthew said, but i&#039;d still think that if you were using the filtering to find a node at a certain level, with an attribute of a certain value, then internally it would deal with the fact that the node it&#039;s querying does not contain an attribute of that name. As you&#039;re obviously not looking for that node.&lt;/p&gt;

&lt;p&gt;Surely it would make more sense to return either the result or nothing at all, rather than throwing an error?&lt;/p&gt;

&lt;p&gt;I don&#039;t think you can throw it in a try/catch as suggested either, as once the error is thrown, the loop if broken.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Cheers for this, you&#8217;ve just stopped my small headache turning into  massive one. I understand what matthew said, but i&#8217;d still think that if you were using the filtering to find a node at a certain level, with an attribute of a certain value, then internally it would deal with the fact that the node it&#8217;s querying does not contain an attribute of that name. As you&#8217;re obviously not looking for that node.</p>

<p>Surely it would make more sense to return either the result or nothing at all, rather than throwing an error?</p>

<p>I don&#8217;t think you can throw it in a try/catch as suggested either, as once the error is thrown, the loop if broken.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Derek</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39971</link>
		<dc:creator>Derek</dc:creator>
		<pubDate>Wed, 18 Nov 2009 16:23:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39971</guid>
		<description>&lt;p&gt;you can throw it in a try/catch&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>you can throw it in a try/catch</p>]]></content:encoded>
	</item>
	<item>
		<title>By: matthew</title>
		<link>http://www.eightdotthree.net/2009/10/referenceerror-error-1065-re-e4x-xml-search/comment-page-1/#comment-39963</link>
		<dc:creator>matthew</dc:creator>
		<pubDate>Wed, 28 Oct 2009 23:24:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.eightdotthree.net/?p=299#comment-39963</guid>
		<description>&lt;p&gt;This kind of makes sense when you think about what the predicate search is actually doing: basically, iterating over the whole XMLList and running the filter in the scope of each item.  In other words, an XMLList predicate filter like &lt;code&gt;myXMLList.(@attr == &quot;value&quot;)&lt;/code&gt; is the XMLList equivalent of the following for Arrays:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;
function f(item:Object):Boolean
{
    with (item)
        return @attr == &quot;value&quot;;
}
myArray.filter(f);
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;In this context, it makes a lot more sense why you would get that error: you&#039;re trying to access the &lt;code&gt;@attr&lt;/code&gt; property of an object that doesn&#039;t have one.  Using the &lt;code&gt;attribute()&lt;/code&gt; function doesn&#039;t throw an error.  What might not be immediately clear is that the &lt;code&gt;attribute()&lt;/code&gt; function that we&#039;re calling is the instance method on the current XML object.  Again, this is more clear in the Array.filter example:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;
function f(item:Object):Boolean
{
    with (item)
        return attribute(&quot;attr&quot;) == &quot;value&quot;;
}
myArray.filter(f);
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Here, it becomes more obvious that 1) the &lt;code&gt;attribute()&lt;/code&gt; function is being called on every iteration (i.e. once per each item in the Array) and 2) the method being called is the one defined on the item itself (because that&#039;s the first/only thing in the scope chain to define the function).  If one of the items in the Array did not define an &lt;code&gt;attribute()&lt;/code&gt; method, then we would get an error on that iteration, just like we did when the item didn&#039;t define an &lt;code&gt;@attr&lt;/code&gt; property.  So when we use the &lt;code&gt;attribute()&lt;/code&gt; method, we are actually making one assumption (which I alluded to before): that each item in the collection defines that method.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>This kind of makes sense when you think about what the predicate search is actually doing: basically, iterating over the whole XMLList and running the filter in the scope of each item.  In other words, an XMLList predicate filter like <code>myXMLList.(@attr == "value")</code> is the XMLList equivalent of the following for Arrays:</p>

<p><pre><code>
function f(item:Object):Boolean
{
    with (item)
        return @attr == "value";
}
myArray.filter(f);
</code></pre></p>

<p>In this context, it makes a lot more sense why you would get that error: you&#8217;re trying to access the <code>@attr</code> property of an object that doesn&#8217;t have one.  Using the <code>attribute()</code> function doesn&#8217;t throw an error.  What might not be immediately clear is that the <code>attribute()</code> function that we&#8217;re calling is the instance method on the current XML object.  Again, this is more clear in the Array.filter example:</p>

<p><pre><code>
function f(item:Object):Boolean
{
    with (item)
        return attribute("attr") == "value";
}
myArray.filter(f);
</code></pre></p>

<p>Here, it becomes more obvious that 1) the <code>attribute()</code> function is being called on every iteration (i.e. once per each item in the Array) and 2) the method being called is the one defined on the item itself (because that&#8217;s the first/only thing in the scope chain to define the function).  If one of the items in the Array did not define an <code>attribute()</code> method, then we would get an error on that iteration, just like we did when the item didn&#8217;t define an <code>@attr</code> property.  So when we use the <code>attribute()</code> method, we are actually making one assumption (which I alluded to before): that each item in the collection defines that method.</p>]]></content:encoded>
	</item>
</channel>
</rss>
