a work on process

Viewing posts in category: XML

An article I wrote has just been published over at InfoQ. It’s called Versatile RESTful APIs Beyond XML and shows how easy it can be to extend Rails’ RESTful behaviour to input and output resources not only as XML but also as JSON and Microformatted HTML.

The article builds on some posts on this blog, such as Intercepting Microformats In Rails Input, but offers a bit more context. The timing of the article fits nicely with a post on the microformats-rest list about Rails, REST and microformats, so hopefully we’ll see more discussion of these concepts over the coming weeks.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

Relax over REST

27 February 2007 (1:19 pm)

By James Stewart
Filed under: XML
Tagged: , , ,

Mark Nottingham has a good post running through a few topics on which people get needlessly caught when designing RESTful applications. If you’re new to working on RESTful application design (as many rails developers are) it’s worth checking out to save yourself needless anguish.

Thankfully for Rails developers at least some of the issues he identifies will be a little simpler than they might be for people designing systems from scratch. In particular, while there are a few URL design choices (numeric IDs, other parameters, or a hybrid? nested vs. flat?) the conventions are good and changing isn’t all that hard.

And while some sort of schema definition is important to ensure that server and client can be sure they’re speaking the same language, for those using tools like ActiveResource which take full advantage of dynamic languages, there’s a little more flexibility than there may have been before.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

XML::Mapping and text nodes with attributes

8 January 2007 (1:06 pm)

By James Stewart
Filed under: XML
Tagged: , ,

While working on an API interface I’ve been playing around with XML::Mapping, an XML-to-object wrapper for ruby. The main reason to use it is that it allows me to easily build an interface similar to that used in Cody Fauser’s Ebay API client which will also be used in the same application.

Generally I’ve been very happy with the library, though at some point it would be nice to have a class generator which will take the XSD file and write most of the code for me, but scour the documentation as I may I couldn’t find an easy way to add attributes to a standard text-holding node. It’s easy enough to get:

<company>
  <person id="123">
	<name>First Person</name>
  </person>
</company>

I couldn’t find a way to get:

<company>
  <person id="123">First Person</person>
</company>

without resorting to xpath wrangling.

Thankfully the library allows you to define your own node types, so once I added

module XML
  module Mapping
    class TextNodeWithAttributes < SingleAttributeNode
 
      def initialize_impl(path)
        @path = XML::XXPath.new(path)
      end
 
      def extract_attr_value(xml)
        default_when_xpath_err{ @path.first(xml).text }
      end
 
      def set_attr_value(xml, values)
        @path.first(xml, :ensure_created=>true).text = values.delete(:value)
        @path.first(xml, :ensure_created=>true).add_attributes(values) unless values.empty?
      end
    end
  end
end

to my code and then included it with

XML::Mapping.add_node_class XML::Mapping::TextNodeWithAttributes

I could specify the above with the class:

module MyNamespace
  class Company
    text_node_with_attributes :person, 'person'
  end
end

and create it with

MyNamespace::Company.new(:person => {:value => 'My Person', 'id' => '123'})

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

Namespaces, attributes and content in rxml

22 August 2006 (4:03 am)

By James Stewart
Filed under: XML
Tagged: , , ,

Rails’ RXML templates (powered by Builder) are a great way to generate various different types of XML output from your application, but the documentation could be lacking. I’ve been working with namespaced content for a while but I’ve spent quite a while today trying to work out how to add an element in an explicit namespace, with attributes and text content.

To create an ‘id’ element is straightforward:

xml.id 'my-id-here'

and then to put that tag in the ‘foo’ namespace you need:

xml.foo :id, 'my-id-here'

To create children of that element (say xhtml content in an atom feed) you need:

xml.content :type => 'xhtml' do 
  xml.xhtml :div do
    xml.p entry.excerpt
  end
end

And the final piece of the puzzle, and the end to that particular bout of frustration is the text! method. To use my exact example:

xml.georss :point, :featuretypetag => 'wifi' do 
  xml.text! entry.latitude + ' ' + entry.longitude
end

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

Feeds in the Blogger Beta Updates

15 August 2006 (8:54 am)

By James Stewart
Filed under: Commentary, Notes, XML
Tagged: , , , ,

After TechCrunch posted about the new version of blogger (currently in beta) I decided to give it a look, particularly to see what was going on with their feed support as TechCrunch claim that blogger would be switching to RSS2 for its feeds (revisiting TechCrunch it seems they’re now saying RSS2 will be offered in addition to atom so I don’t know if I misread that or it’s been updated. Personally I don’t see the point of adding RSS2 when you have Atom, and wonder if it might be confusing for some users, but I guess someone must disagree).

Creating a new blog on the beta service was as easy as we’ve come to expect and publishing an entry definitely feels faster, even if a single entry isn’t really a good basis for comparison. It’s nice to see tag support (even if they’ve chosen to call them ‘labels’) and their inclusion will definitely make projects like my Greenbelt Collage much easier to explain to users.

So far, it looks as though blogger is sticking with atom with feeds switched on by default, and finally upgrading to valid 1.0 feeds for both entries and comments. The default setting is for the full text of both posts and comments to be available in Atom 1.0 feeds, with links to those feeds included by default in the templates. Support of Atom 1.0 rather than RSS 2 is very good news for those of us developing tools that aggregate or remix feed content, if for nothing more than its support for unique IDs.

Unfortunately there don’t seem to be autodiscovery links in the page headers and with the ability to edit the HTML directly not yet in place, there’s not even a way to add them manually. As feed support in browsers and OSs becomes more commonplace, it’s definitely to be hoped that autodiscovery links will be included by default to help keep feed support consistent.

Tags: , , , ,

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 
Next Page »