Monday, 23 November 2009

XML Namespaces

Recently I have been lucky enough to be working on a project that uses LCDS so I don’t have to write XML translators – all the objects arrive from server ready typed – it is soooo much easier and saves an awful lot of time.

At home though I have started working with the Picasa data API which means I am back to writing translators.
This is a job I really don’t like – it never works the first time and takes a lot of trial and error to get it write. I am actually going to write a base translator class to make it a bit easier the next time I have to do it.

Getting to grips with xml can be tricky but when namespaces are involved it gets exponentially more difficult and annoying!

I’ll make a note of the syntax of how to deal with namespaces here so that next time I’ve forgotten how to do it I can look it up.

I am trying to retrieve the href of the link node below with the relevance of self:


My first attempt was as follows:

var href : String =’self’)[ 0 ]@href;

but that didn’t work. The give away is this line:


declaring the default namespace for the xml. What worked in the end was this:

var atom : Namespace = new Namespace( "" );
var href : String = xml.atom::link.( @rel == 'self' )[ 0 ]@href;

Hopefully that’ll save me (and maybe you) a few hours in the future.

Sunday, 15 November 2009

Picasa Web Albums Data API

I have previously tried to get Flex to play nicely with the Picasa API. I use Picasa a lot and host all my pictures there so to be able to do things with them with Flex would be very useful.

Before I have had issues as there was no crossdomain.xml but having had a look at the docs today this seems to now be fixed (or I missed it last time) as detailed here.

There are a couple of small projects I want to build on this API so it’s great that I won’t have to proxy these calls through the server.