View Plugin:XMLGrab
Introduction
The XMLGrab plugin allows you to insert the contents of an XML file (or feed, or API response) into Expression Engine weblogs.
See the product page for XMLGrab.
Example
XML file
From: http://twitter.com/statuses/public_timeline.xml
<statuses>
<status>
<created_at>Tue Apr 10 08:03:22 +0000 2007</created_at>
<id>23447691</id>
<text>setting things up in our temporary office in berlin, mitte.</text>
<user>
<id>60383</id>
<name>Tilman</name>
<screen_name>Tilman</screen_name>
<location>Nürnberg, Germany</location>
<description>Saving the world in style.</description>
<profile_image_url>http://assets3.twitter.com/system/user/profile_image/60383/nor…</url>
<protected>false</protected>
</user>
</status>
<status>
<created_at>Tue Apr 10 08:03:21 +0000 2007</created_at>
<id>23447661</id>
<text>参加 iptv-world 组织的2007年度 IPTV ...</text>
<user>
<id>795506</id>
<name>Michael Zheng</name>
<screen_name>tvdotnet</screen_name>
<location>Beijing, China</location>
<description></description>
<profile_image_url>http://assets0.twitter.com/system/user/profile_image/795506…</profile_image_url>
<url>http://mediaedge.blogbus.com/</url>
<protected>false</protected>
</user>
</status>
...
</statuses>
Template code
{exp:xmlgrab url="http://twitter.com/statuses/public_timeline.xml"
itempath="/statuses/status"
weblog="2"
title="text"
date="created_at"
use="user/name|text"
fields="feeds_url|feeds_body"}
Parameters
- url=“http://www.path.to/file.xml”
- itempath=”/statuses/status”
- weblog=“1”
- author=“3”
- title=“title”
- date=“pubDate”
- use=“link|description”
- fields=“extended|body”
- category=“2” or category=“flickr”
- category_field=“media:category”
- category_delimiter=“SPACE”
- category_group=“2”
- unique=“extended”
url=
url=“http://www.path.to/feed.rss”
The url of the feed to import
itempath=
itempath=”/statuses/status”
The xpath to the node you want to loop over. This will depend on the format of you XML file. For example though, for an RSS 2.0 feed in the format:
<rss version="2.0">
<channel>
<title></title>
<link></link>
<description></description>
<language>en</language>
<ttl>60</ttl>
<item>
<title>Article 1</title>
<link>/story/3487.html</link>
<description>Description 1</description>
<pubDate></pubDate>
</item>
<item>
<title>Article 2</title>
<link>3399.html?rss=1</link>
<description>Description 2</description>
<pubDate></pubDate>
</item>
...
it would be:
itempath=”/rss/channel/item”
weblog=
weblog=“1”
The id of the weblog to import entries into
author=
author=“1”
The id of the author to associate with the imported entries
title=
title=“title”
The feed element to use as the entry’s title
date=
date=“dc:date”
The feed element to use as the entry’s publish date
use=
use=“link|description”
A ‘pipe’ delimited list of fields from the RSS feed that you want to import
fields=
fields=“magnolia_url|magnolia_body”
The (custom) fields that you want the use= fields inserted into.
The number of fields must match the number in the use= parameter.
category=
category=“2”
or
category=“flickr”
The id or name of the category to put entries in by default
category_field=
category_field=“categories”
The feed element that contains the category (or list of categories) to add the entry to
category_delimiter=
category_delimiter=“SPACE”
The delimiter between categories in the category_field element. Use the value “SPACE” for a space delimiter.
category_group=
category_group=“2”
Categories that do not exist are created automatically. This parameter sets the id of the category group to create new categories in.
unique=
unique=“guid”
The unique field determines which fields are checked to see if the current feed element ahas already been imported. Many feeds have a guid element which identifies a unique item, but you can also define your own combinations to check, eg,
unique=“title,date”
will not import any items with the same title and date as an existing element in the selected weblog.
Note, the field names are the fields set up within your own weblog (ie, title, date, and any custom fields)
the names of the fields in the feed.