FeedAPI is an excellent module to deliver information from the outside world into a Drupal installation. Currently FeedAPI supports to import RSS nodes, which include most applications. But legacy systems (which are probably 3 to 7 years old) and most enterprise information systems have no RSS output that supports only a few fields as a content type. In such an occasion, a more generic format is required to feed data into Drupal with FeedAPI. One of the best practices is to acquire information from legacy systems in XML format that is supported by a FeedAPI’s parser (which is already described in the previous post). Although any format is parsable, XML is more intuitive.
Generally speaking, FeedAPI accepts a list of items that are described in the same format. To generalize FeedAPI usage of feeds, a simple XML format is proposed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8"?> <feed xmlns:foo="http://example.com/foo" id="an id for a feed" title="the title for a feed" description="the description for this feed" link="the link to be imported as the original_url, can be ignored"> <node id="a unique id" title="the title to be imported as the node title" description="the description to be imported as the node description" link="the link to be imported as the original_url, which can be ignored"> <data> <foo:id>foo's id</foo:id> <foo:first-name>foo's name</foo:first-name> <foo:last-name>foo's last name</foo:last-name> <foo:email>foo's email</foo:email> <foo:website>http://foohomepage.com</foo:website> </data> </node> </feed> |
In the above example, a simple XML wrapper is used to encasulate the actual data (foo’s item description). Foo’s original XML elements an be directly ecansulated into the data field with proper namespace settings.
Elements
feed
This element has four attributes, including id
, title
, description
, and link
. id
is a unique identification string in a drupal installation, it is imported into drupal as the guid
field. title
and description
are respectively title and description in a FeedAPI feed. When a feed in the above format is imported, these two fields are imported as the feed’s title and description. link
is imported as the original_url
field for a FeedAPI feed. In current implementation, guid
and original_url
must have at least one exist. In my SimpleXML parser implementation, guid
(the id
attribute) is required.
The feed
tag consists of a series of node
tags.
node
The node
tag is a container for a node’s details. Currently only data
tag is allowed under node
tag. Other tags can also be added under node
to specify any node information. node
has also the four attributes that are described in feed
to represent drupal-specific meta data.
data
The data
tag is a container of the original data that is converted (or directly copied) from an original XML. A namespace is suggested to indicate the source of the data. Any XML data can be added under data
tag, however, the format must be consistent so the parser is able to get the same set of information for each node.