You are on page 1of 3

Widget XML Specification

Overview

Widgets are embeddable web applications written in XML (and containing HTML and Javascript
for rendering content) which can placed and run within widget containers. The XML contains
instructions on how to render and process a widget and must follow a specific format.

The XML

This is an example of a basic widget written in XML:

<?xml version="1.0" encoding="UTF-8" ?>

<Module>
<ModulePrefs title="example widget">
<Require feature="dynamic-height"/>
</ModulePrefs>
<Content type="html" view="home">
<![CDATA[
<h1>Welcome to Nature Network!</h1>
]]>
</Content>
</Module>

The XML is broken down into distinct sections, with each section providing information about the
widget and how it is to be rendered. (The opening line is a required directive which specifies that
this is an XML document).

Module is used to specify that this is a widget and to enclose all widget instructions.
ModulePrefs contains all meta-data about this widget and any features that are to be utilized by
the widget. (See sections below on Module Prefs and Features for further information).
Content contains all the content for the widget, which should consist of HTML and Javascript.

Module Prefs

The ModulePrefs element contains information regarding the characteristics and processing
rules of the widget. This information can include: title, description, dimension, locale and features
supported by the widget.

The Nature Network container supports all module preferences and does not currently provide
any container-specific attributes.

See http://code.google.com/apis/gadgets/docs/reference.html#Moduleprefs_Ref for further


information on ModulePref attributes.

Features

Features provide extra abilities to a widget and are the primary mechanism for extending basic
widget functionality. Features that are to be used must be declared within the ModulePrefs
element of the widget XML and can be specified as either required or optional:

<ModulePrefs>
<Require feature="opensocial-0.8"/>
<Optional feature="dynamic-height"/>
</ModulePrefs>

Features supported by the Nature Network container:

● OpenSocial
● OAuth
● User Preferences
● Views
● Dynamic Height
● Tabs
● Flash
● Google Analytics
● Mini Messaging

For further information on what these features are and how to use them, see:
http://code.google.com/apis/gadgets/docs/ui.html
http://code.google.com/apis/gadgets/docs/fundamentals.html

The OpenSocial and Views features are most relevant to widgets hosted within the Nature
Network container, and are described in more detail below.

OpenSocial

The Nature Network container is an OpenSocial container which supports OpenSocial widgets
created using versions 0.6 - 0.8.

OpenSocial is an API developed by the OpenSocial foundation which allows for widgets to
access social data when placed on an OpenSocial container. This ‘social data’ includes users,
their relationships with others, and user activity.

To activate OpenSocial in a widget, simply require the feature within the ModulePrefs:

<ModulePrefs>
<Require feature="opensocial-0.8"/>
</ModulePrefs>

To learn more about creating OpenSocial widgets, see: http://wiki.opensocial.org/index.php?


title=Gadget_Developer%27s_Guide

Views

There can be multiple Content sections defined in a widget, with each one representing a given
view of the widget. The Nature Network container supports both home and canvas views.
Home is a small view of the widget which is displayed on the Nature Network Workbench main
page.
Canvas is a larger, full-paged view of the widget which is displayed on expansion of the widget.

To activate the use of views in a widget, simply require the feature within the ModulePrefs:

<ModulePrefs>
<Require feature="views"/>
</ModulePrefs>

To activate the use of a canvas view, simply provide the definition of the canvas view in your
widget:

<Module>
<Content type="html" view="home">
<![CDATA[
...
]]>
</Content>
<Content type="html" view="canvas">
<![CDATA[
...
]]>
</Content>
</Module>

The inclusion of the canvas view will automatically enable the maximize button on your widget
within the Nature Network Workbench.

You might also like