E4X – Updating multiple node values
Something that is often required when processing XML documents is to update a bunch of nodes that are spread throughout the document.
Consider the following XML:
<gallery base="images/projects/"> <project id="1" > <item type="image" thumb="image1.jpg"> <path>l_image1.jpg</path> </item> </project> <project id="2"> <item type="image" thumb="image2.jpg"> <path>l_image2.jpg</path> </item> </project> <project id="3"> <item type="image" thumb="image1.jpg"> <path>l_image1.jpg</path> </item> <item type="image" thumb="image3.jpg"> <path>l_image3.jpg</path> </item> <item type="image" thumb="image4.jpg"> <path>l_image4.jpg</path> </item> <item type="image" thumb="image5.jpg"> <path>l_image5.jpg</path> </item> </project> </gallery>
Lets assume that we need to load the thumbnails of each item specified by the thumb attribute. I often use a base path for the images. It make a lot of sense to include it at document level rather than repeating it in each property value. Doing so reduces file size and also makes path updates quick and painless.
Once the XML document is loaded, the thumb path can be updated with a single line of code:
galleryXML..item.(@thumb = baseUrl + @thumb);
where baseUrl variable holds the base path. Or we can directly substitute with the value of base property like so:
galleryXML..item.(@thumb = galleryXML.@base.toString() + @thumb);
A trace of galleryXML will show that the path of each thumb attribute is prefixed with the base path.
XPath – Tutorial
Spry – a simple introduction
Stumbled on this nice tutorial by Chris Bizzell over at http://www.actionscript.com/Article/tabid/54/ArticleID/Spry—Welcome-to-the-Nieghborhood/Default.aspx
I’ve been wanting to get my hand into Spry for a long time now. This is a nice and quick tute to which explains how to read and display an XML file.
POWERFLASHER SOS
POWERFLASHER SOS (SocketOutputServer) is a XML Socket server with a graphic user interface. Connected clients can send messages to SOS. These messages are shown in SOS. Further on commands from SOS to Client can be sent. These are freely configurable.
