Currently browsing namespace


Namespace for URI Templates?

Thu, 21 Feb 2008 22:09 UTC

I was giving some thought to Joe Gregorio’s latest draft of URI Templates and considering how to use them with paginated feeds.

For example, I have an Atom Feed that includes the following link elements:

<link rel="first" type="application/atom+xml;type=feed" href="http://example.org/content"/>
<link rel="last" type="application/atom+xml;type=feed" href="http://example.org/content?idx=48336"/>
<link rel="previous" type="application/atom+xml;type=feed" href="http://example.org/content?idx=1"/>
<link rel="next" type="application/atom+xml;type=feed" href="http://example.org/content?idx=41"/>

It’s obvious that, to traverse the Feed, the Client need only change the “idx” parameter. So, why not tell the Client that they can do this with a URI Template?

To do this, I could use a template element, but in what namespace? That’s where my problem comes in.

I’ve searched all over the W3C URI mailing list, in addition to the Atom lists and all the usual suspects, but I haven’t seen where anyone has made a formal a recommendation.

I did stumble across a post by James Snell in which he proposed an approach to create a namespace to describe URI template variable names, but the post is stale (October 2006) and the approach doesn’t address the template itself.

So, without a good lead to go on and a strong desire not to create my own namespace, I sent an e-mail to Mark Nottingham asking if he would be interested in considering an update of the fh namespace to include a template element for this purpose?

For example:

<fh:template>http://example.org/content{-prefix|?idx=|index}</fh:template>

But then I found recent post by Joe Gregorio that doesn’t specifically address this, but does include in one of his examples the following snippet, defining a “t” namespace for the link_template element.

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
       xmlns:t="http://blah...">   
  <t:link_template rel="sub" href="http://example.org/edit/first-post/{-listjoin|;|id}"/>
...

I don’t know how I feel about having a general purpose template element in a separate namespace rather than having various namespaces define their own template elements. In the fh:template example, the template is within the “feed history” namespace, which gives it meaning; the URI template provided is for feed histories. If there is a separate namespace, then the template can lose context.

So, what do you think? Should there be a separate XML namespace to define URI templates? Is there an effort to do so, and where is the discussion occurring if there is?

Comments No Comments  Permalink Permalink  Tags Tags: , , , ,


Flickr Namespace and array_multisort() Issues

Fri, 15 Dec 2006 18:15 UTC

Aaron Wormus recently criticized me on IRC for putting too much thought and effort into blogging. He may have a point there. I’ve got a huge list of things I want to write about, but I haven’t put forth the effort because I do take too much time to write a post. So, here goes one for writing up a quick post . . .

I recently upgraded a few things around here (in particular, an upgrade to PHP 5.2), and I noticed two issues that occurred after the upgrade:

  1. My Flickr photo feed no longer worked, and
  1. My blogroll was no longer sorting alphabetically

    I easily solved both of these issues:

    The Flickr photo feed

    I’m not entirely sure whether this problem was a result of the PHP 5.2 upgrade and SimpleXML becoming more particular about namespaces or Flickr simply changing the namespace string in their feed. I believe it was the latter. In short, my code stopped working because the namespace lacked a trailing slash (/). It would’ve been great if Flickr had notified everyone about this first.

    The code looked something like this:

    <?php
     
    $flickr_rss = simplexml_load_file('http://www.flickr.com/services/feeds/photos_public.gne?id=49198866@N00&format=rss_200');
     
    foreach ($flickr_rss->channel->item as $item)
    {
        $link   = (string) $item->link;
        $media  = $item->children('http://search.yahoo.com/mrss');
        $thumb  = $media->thumbnail->attributes();
        $url    = (string) $thumb['url'];
        $width  = (string) $thumb['width'];
        $height = (string) $thumb['height'];
        $title  = (string) $item->title;
     
        // display image here
    }
     
    ?>

    Note the namespace listed in $item->children(‘http://search.yahoo.com/mrss’);. It’s lacking a trailing slash. This was never a problem before, but it seems that the Flickr feed changed to include a trailing slash, so SimpleXML was no longer able to properly get the data. I simply changed it to http://search.yahoo.com/mrss/ (note the trailing slash), and all worked fine.

    Blogroll sorting

    This was more than likely a result of the upgrade to PHP 5.2, though I can’t be sure. My blog sorting code worked like this:

    <?php
     
    // sort by name
    $name = array();
    foreach ($blogs as $k => $v)
    {
        $name[$k] = $v['name'];
    }
    array_multisort($name, SORT_ASC, $blogs);
     
    ?>

    Unfortunately, after the upgrade, this no longer worked. I had to add the SORT_STRING flag as a parameter to array_multisort() so that the line now reads:

    <?php
     
    array_multisort($name, SORT_ASC, SORT_STRING, $blogs);
     
    ?>

    And that fixed it.

    Just thought I’d share the info in case this helps anyone.

    Comments 2 Comments »  Permalink Permalink  Tags Tags: , , , ,