Category Archives: developer

developer technical thoughts

Names and learning stuff

Was chatting to one of my colleagues this morning. She mentioned that the DVLA had screwed up her driving licence application and put both her names as last names.

This meant that she couldn’t log in to the form on the website, which was causing all sorts of hassle to get sorted out.

At first glance,its probably easy enough to think, well surely the system can be programmed to always have a  first name. Until a few days ago I would have said the same thing but then found this blog post.

The comments on that page are a lot more reasoned and thought out than the average youTube “You is Stupid” sort of respone and one of the commenters asked for examples of number 40. People have names .

Patrick the Author responded with ;

Someone born into slavery in the Sudan, a woman born in rural China, an American baby recovered after being born into a toilet, a feral child, an amnesiac, etc, etc. go here for more info.

The first two especially struck me as being really powerful. Not having a name because you are born a slave  or a woman in rural China makes our frustrations at not been able to log on to our governments online Driving licence registration system pale in comparison.

It also struck me as interesting that I’d started reading an article about name validation and U.I design and ended up thinking about human rights

So the next time you hear one of those funny computer says no  (its little Britain so bit of NSFW video)  stories in the news its worth remembering that this stuff isn’t as simple as it might seem at first.

developer technical

Something like this

When I said the BBC should be getting involved with open sensors and data, the open citizen kit was the sort of thing i was thinking about

developer technical

Dear BBC why oh Why oh Why

So this week the BBC launched their own smart phone Weather App I downloaded it and its very nice, it seems to work ok but can’t say I was blown away.

What I was more surprised with was that the BBC have made a Weather App at all. I’m not sure that its something the BBC should even be doing.

Let me explain,a few years ago there was this great project called Backstage that was an early project to open up web data and allow individuals to re-mix and re-interpret products and services.

The BBC provided access to xml feeds and APIs such as its weather and traffic data and encouraged people to play,learn and feed back.

I discovered the project quite late on in its life just as I was starting to learn some programming. it was the 1st time i had joined in with something that was real life and not a project out of a book or trivial academic exerscise and it was  a great learning experience.

At the time I used the Linux KDE3 desktop so I decided to make a desktop widget that would display a summary of the weather and the temperature. If I recall correctly it was done in python,  the biggest obstacle was dealing with the XML. It turned out that the BBC XML feed  was a real stinker putting the entire forecast,temperatures, wind strength etc into 1 tag. This meant i had to learn regular expressionsto be able to extract what I wanted, something that still fills me with dread every time I think i might have to use them.

So I built the Widget and it worked ok, although it tended to crash after a while and also the forecast location was hardcoded into it. Very soon KDE3 was replaced with KDE4 that used a different framework for its desktop widgets. Even though I was too shy to post my code anywhere for fear that it would be critiscised by what I considered to be the ‘proper programmers’ I did start to engage with the community and post to the mailing list occasionally.

So the project wound up and I moved on to other things, started to learn Java through the O.U (Tip: don’t its a massive waste of money) ,move onto Android(Tip: do) and dip my feet into various other technologies that  have taken my fancy.

So when the Weather App was Launched I was surprised that the BBC hadn’t learn’t a lesson from its own Backstage project and also looked at the world around them.   They led the way in opening up  data.  I would have much preferred them to offer something as groundbreaking again. What about encouraging hardware Internet of things type  projects, sensors  such as Thermodo or people running their own weather stations to feed data back to the BBC to improve their own data.

Don’t want to get all Point of View but come on BBC could do better.

developer technical

Parsing XML with PHP

This post really is one of those that is as much for my benefit than anyone else’s but it may just be some use to other people.

I have seen a lot of tutorials that try to explain XML parsing but none have really hit the spot for me,so I thought another may be useful.

I think what was always missing was the part after getting the xml, there always seems to be some magic wand waving and out pops the needed data.

I have been working on a very simple HTML5 weather App recently that takes a RSS feed processes it and displays just the current weather condition and temperature, told you it was simple.

I managed to get the Parsing of the Weather Feed done by following a article that described exactly how to parse the Yahoo weather feed that I am using. I sort of understood the process,but not fully.  The next stage was to use the HTML5 geolocation API and then send this to the Yahoo Boss placefinder to return a WOEID that I could plug into the weather feed url, to provide the  local weather, really a necessitiy for a mobile App.

By modifying the example found at:  to work with the placefinder  as shown below.


    $url = "";  

    $cc_key  = "My Consumer Key";  
    $cc_secret = "My Consumer Secret";  

    $args = array();  

    $args["location"] = "51.5082629, -0.1547288";
    $args["gflags"] = "R";

    $consumer = new OAuthConsumer($cc_key, $cc_secret);  
    $request = OAuthRequest::from_consumer_and_token($consumer, NULL,"GET", $url,  
    $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);  

    $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));  
    echo $url;
    $ch = curl_init();  
    $headers = array($request->to_header());  
    curl_setopt($ch,CURLOPT_ENCODING , "gzip");   
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  
    //print_r("Request Headersn");  
    $rsp = curl_exec($ch); 
    $xml = simplexml_load_string($rsp);
    print_r("nHere is the XML response for Placefindern");  

//Below is the parsed WOEID value
$woeid = $xml->placefinder[0]->results[0]->result->woeid;
echo $woeid;

This gives the following xml response

<?xml version="1.0" encoding="UTF-8"?>
<bossresponse responsecode="200">
  <placefinder start="0" count="1" request="location=51.5082629%2C%20-0.1547288&amp;gflags=R">
        <name>51.5082629, -0.1547288</name>
        <line1>51.5082629, -0.1547288</line1>
        <line3>W1K 7</line3>
        <line4>United Kingdom</line4><house></house><street></street><xstreet></xstreet><unittype></unittype><unit></unit>
        <postal>W1K 7</postal>
        <country>United Kingdom</country>
        <uzip>W1K 7</uzip><hash></hash>

The item that we are intersested in is at the very bottom of the output


I think one of the problems I have had in understanding how to parse XML is that I was expecting to be able to enter a command a supply the XML  tag as  a parameter and get the data back, well it doesn’t quite work like  that.

I think the best way to think about it is whenever the word parse is used is to swap it for ‘get the data from the xml’, in my head.

So lets crack on.

To Parse the XML we are going to use simpleXML , there are other ways to parse XML in PHP but for files that aren’t hundreds of Megs simpleXML is regarded to be the best, it was introduced in PHP5 to address the need of an XML parser that is easy to use.

So first stage  is to create a simplexml object :

$xml = simplexml_load_string($rsp);

The next step is to create a path to the woeid in the xml object, probably the easiest way to do this is to work backwards.

Ignoring all of the other data and just concentrating on the <woeid> tag we can see the structure of the XML looks something like








In the xml file the <bossresponse responsecode=”200”> is the route tag. All xml files have a route tag which must contain all the other contents of the xml file, so we don’t need to refer to it when getting the woeid.

Looking through the xml response. the tag placefinder only contains further levels of tags no any actual data so we need to think of it as an array that contains other arrays hence referring to it as placefinder[0]. The same is trued for results. the result tag contains the woeid tag and the woeid tag contains the actual data we want, so both of those can be referred to directly.

$woeid = $xml->placefinder[0]->results[0]->result->woeid;

And that is all there is to it. If you are struggling to understand hot to parse xml feeds with php I would encourage you to have a go,read a few different articles and look at Stack overflow if you want more information