XML Tutorials

  Home arrow XML Tutorials arrow Using Modules in Your RSS Feed
XML TUTORIALS

Using Modules in Your RSS Feed
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-10

    Table of Contents:
  • Using Modules in Your RSS Feed
  • blogChannel Module
  • Simple Semantic Resolution Module
  • ICBM Module

  •  
     

    SEARCH CODEWALKERS

    Using Modules in Your RSS Feed


    (Page 1 of 4 )

    In this second part of a three-part series, you will learn how to extend your RSS feed's range of expression by using modules. This article is excerpted from chapter four of the book Developing Feeds with RSS and Atom, written by Ben Hammersley (O'Reilly; ISBN: 0596008813). Copyright 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Introducing Modules

    Modules are additional sets of elements, giving the feed a greater range of expression: they allow the specification to be extended without actually being changed, which is a very clever trick. You can make your own module match any data you might wish to syndicate. Admittedly, most aggregators will ignore it, but your own applications can take advantage of it. And, happily, the most popular modules are increasingly being supported by the latest aggregators as a matter of course.

    Modules in RSS, both Versions 2.0 and 1.0, are created with a system known as XML Namespaces. Namespaces are the XML solution to the classic language problem of one word meaning two things in different contexts. Take "Windows," for example. In the context of houses, "windows" are holes in the wall through which we can look. In the context of computers, "Windows" is a trademark of the Microsoft Corporation and refers to its range of operating systems. The context within which the name has a particular meaning is called its namespace.

    In XML, you can distinguish between the two meanings by assigning a namespace and placing the namespace's name in front of the element name, separated by a colon, like this:

      <computing:windows>This is an operating system</computing:windows>

      <building:windows>This is a hole in a wall</building:windows>

    Namespaces solve two problems. First, they allow you to distinguish between different meanings for words that are spelled the same way, which means you can use words more than once for different meanings. Second, they allow you to group together words that are related to each other; for example, using a computer to look through an XML document for all elements with a certain namespace is easy.

    Both RSS 1.0 and 2.0 use namespaces to allow for modularization. This modularization means that developers can add new features to RSS documents without changing the core specification.

    Modularization has great advantages over the older RSS 0.9x's method for including new elements. For starters, anyone can create a module: there are no standards issues or any need for approval, aside from making sure that the namespace URI you use has not been used before. And, it means both RSS 1.0 and 2.0 are potentially far more powerful than RSS 0.9x ever was.

    A module works in the actual RSS document by declaring a namespace within the root element of the feed and by prefixing the element's names with that namespace prefix, like so:

      <?xml version="1.0"?>
      <rss version="2.0" xmlns:blogChannel="http://backend.userland.com/
    blogChannelModule">
      ... 

        <blogChannel:blink>http:// www.benhammersley.com</blogChannel:blink>
      ...

    You should note that the URI the namespace declaration points to is the unique identifier of the namespace and not the namespace prefix. In other words, from the perspective of a program processing XML, this:

      <?xml version="1.0"?>
      <rss version="2.0" xmlns:blogChannel="http://backend.userland. com/blogChannelModule">
      ...

        <blogChannel:blink>http:// www.benhammersley.com</blogChannel:blink>
      ...

    is absolutely identical to this:

      <?xml version="1.0"?>
      <rss version="2.0" xmlns:bingbangbong="http://backend.userland.com/
      blogChannelModule">
      ...

        <bingbandbong:blink>http:// www.benhammersley.com</bingbangbong:blink>...

    This will become clear as we study some common modules. It is customary, and also very good manners, to have documentation for the module to be found at the namespace's URI, but this isn't technically necessary. As discussed in Chapter 11, the different feed standards have different scopes for the form this documentation can take. The presence of anything at all at the namespace URI is entirely optional, both in terms of RSS and within the scope of the broader XML specification itself.

    More XML Tutorials Articles
    More By O'Reilly Media

    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax

    Developer Shed Affiliates

     



    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap