Let’s say you have the following xml for greeting cards.
-
<designlist>
-
<design
-
id="123"
-
title="Happy Hanukkah"
-
previewImageUrl="assets/demo/images/g0022_4×6h_preview.jpg"
-
thumbImageUrl=""
-
<tags>
-
<tag id=‘1231′></tag>
-
<tag id=‘3242′>Hanukkah</tag></code></blockquote>
-
</tags>
-
<code> </design></code>
-
<p align="left"> </p>
-
-
<p align="left"><code><design
-
</code>
-
<blockquote><code> id="456"</code>
-
<code> title="Happy New Year"</code>
-
<code> previewImageUrl="assets/demo/images/g0412_4×6h_preview.jpg"</code>
-
<code> thumbImageUrl=""></code>
-
<code> <tags></code>
-
<blockquote><code> <tag id=’1231′>Holiday</tag></code>
-
<code> <tag id=’2342′>New Year</tag></code></blockquote>
-
<code> </tags></code>
-
<code></code></blockquote>
-
<p align="left"><code> </design></code></p>
-
<p align="left"> </p>
-
-
<p align="left"><code><design
-
</code>
-
<blockquote><code> id="8284"</code>
-
<code> title="Merry Xmas"</code>
-
<code> previewImageUrl="assets/demo/images/g0256_4×6v_preview.jpg"</code>
-
<code> thumbImageUrl=""></code>
-
<code></code></blockquote>
-
<blockquote><code> <tags></code>
-
<blockquote><code> <tag id=’1231′>Holiday</tag></code>
-
<code> <tag id=’3242′>XMas</tag></code>
-
<code> <tag id=’8323′>Christmas</tag></code></blockquote>
-
<code> </tags></code>
-
<code></code></blockquote>
-
<p align="left"><code> </design></code></p>
-
<p align="left"> </p>
-
-
<p align="left"><code><design
-
</code>
-
<blockquote><code> id="8284"</code>
-
<code> title="Happy Happy Happy"</code>
-
<code> previewImageUrl="assets/demo/images/g0055_4×6v_preview.jpg"</code>
-
<code> thumbImageUrl=""></code>
-
<code></code></blockquote>
-
<blockquote><code> <tags></code>
-
<blockquote><code> <tag id=’1231′>Holiday</tag></code>
-
<code> <tag id=’3242′>Happy</tag></code>
-
<code> <tag id=’3242′>Wonderful</tag></code></blockquote>
-
<code> </tags></code>
-
<code></code></blockquote>
-
<p align="left"><code> </design></code></p>
-
</blockquote>
-
<code></designlist></code>
-
-
<code></design></code>
And let’s say we wanted to return the titles for designs for that are tagged with “New Year”. This is tricky because the tags are further down the XML tree than the title, which is an attribute of the design itself. How would we express this in e4x and actionscript?
var titles:XMLList = designViewerPanel.designListXml.design.@title.(parent().design.tags.(tag==”New Year”));
The key here is to use the parent() function, which returns us back to the top level of the xml tree. We can then express the particular tag we are looking for.
I still haven’t figured out how to do the same expression with out specifying the designs.tags…in other words, I’d like to say something like
(parent()..(tag==”New Year”))
but when I try this I get an error…actionscript doesn’t seem to like the parenthesis next to ‘tag’. Ideas anyone?
Post a Comment