Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoerrmann committed Jun 23, 2014
1 parent ddc0ebe commit 084930f
Showing 1 changed file with 11 additions and 79 deletions.
90 changes: 11 additions & 79 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,26 @@

XML Importer is a way of creating repeatable templates to import data from XML feeds directly into Symphony sections. It provides a way of mapping content from XML nodes directly onto fields in your sections, and the ability to both create new and update existing entries.

## Installation
## Sources

1. Upload the `xmlimporter` folder to your Symphony `/extensions` folder
2. Enable it by selecting "XML Importer" on the System > Extensions page, choose Enable from the with-selected menu, then click Apply
3. Use the extension from the Blueprints > XML Importers menu
As of version 3, XML Importer uses Data Sources to import data:

- If you'd like to import external data, please have a look at [Remote Data Source]() which accepts XML, JSON or CSV sources.
- If you'd like to alter existing data, you can make use of standard section Data Sources.

## Creating an Importer (tutorial)
An Importer is similar to a Dynamic XML Datasource in its configuration. Let's create a fictitious importer to store your Twitter messages into a section named "Tweets" that has three fields:
If you want to use the same importer for different input sources, you can modify the URL of the run:

* Permalink (Text Input)
* Date (Date)
* Tweet (Textarea)


### Essentials

Start by creating a new Importer and give it a sensible **Name** such as `Tweets` and add any notes into the **Description** field: `Import Tweets from user's public RSS timeline`.


### Source

This is where we define the XML feed. Start by providing the feed URL, for example mine is:

http://www.twitter.com/statuses/user_timeline/12675.rss

Take a look at the source of this feed and you'll see that it uses XML namespaces (the `xmlns` attributes). To be able to traverse this feed properly the XML Importer needs to know about these namespaces, so click **Add item** under the **Namespace Declarations** region to add the Name/URI values for each namespace:

* Name: `rss`, URI: `http://www.w3.org/2005/Atom`
* Name: `georss`, URI: `http://www.georss.org/georss`

**Included Elements** is an XPath expression representing each XML node that you want to convert into a Symphony entry. In our example we want to loop over each `<item>` node in the RSS feed:

/rss/channel/item

This can also be written as:

//item


### Destination

Now we configure the values for each field in our new entry. Start by selecting the section into which we want to create new entries (`Tweets`). The dropdown under **Fields** will now be filled with the name of each field in this section. We are going to store values for each of the Permalink, Date and Tweet fields.

Click **Add item** to configure the `Permalink` field. You will see three options appear: **XPath Expression**, **PHP Function** and **Is unique**.

Since our **Included Elements** are going to be `<item>` elements from the RSS feed, here is an example:

<item>
</item>

The **XPath Expression** for the `Permalink` field is therefore going to be relative to an `<item>` element. To get the tweet text the XPath would be:

permalink/text()

Remember we want the text value (`text()`) and not the element itself!

**PHP Function** can be left blank, but is used for more complex processing of the selected value before saving. Be sure to check the **Is unique** radio button for the `Permalink` field so that duplicates cannot be created — this prevents the same tweets being added every time the importer is run.

Repeat the above step for the remaining fields. Your **Fields** options should eventually look like:

* **Permalink** XPath Expression: `permalink/text()`, PHP Function: (blank), Is unique: `Yes`
* **Date**, XPath Expression: `published/text()`, PHP Function: (blank), Is unique: `No`
* **Description**, XPath Expression: `description/text()`, PHP Function: (blank), Is unique: `No`

Finally, untick the **Can update existing entries** checkbox. When used in conjunction with the **Is unique** selection, this option allows the importer to update entries where the "unique" value matches. Twitter doesn't allow you edit Tweets once published, so this option isn't required.

Save your importer.


## Run an Importer

From the XML Importers list, click a row to highlight the importer and select **Run** from the **With Selected...** dropdown.

If you want to use the same Importer in multiple feeds (if you have more than one Twitter feed, for example) you can modify the URL of the Run URL. By default our Twitter importer will be executed this this URL:

/symphony/extension/xmlimporter/importers/run/twitter/
http://example.com/symphony/extension/xmlimporter/importers/run/twitter/?source=http://twitter.com/statuses/public_timeline.rss

But the feed URL can be overridden by appending a `source` parameter:
## Destinations

http://example.com/symphony/extension/xmlimporter/importers/run/twitter/?source=http://twitter.com/statuses/public_timeline.rss
Imported data will be stored in the section of your choice (either creating new entries or updating existing ones based on your importer's settings).

When setting up **XPath expressions**, please keep in mind that you explicitely have to reference the text node to get the value of element, e. g. `example/text()`.

## Using PHP Functions

The **PHP Function** field on each imported field allows for some additional processing of the value returned from the XPath Expression. This might be used for parsing out an image URL, converting to Markdown, formatting a date, and so on.
The PHP Function field on each imported field allows for some additional processing of the value returned from the XPath Expression. This might be used for parsing out an image URL, converting to Markdown, formatting a date, and so on.

For example, if you wanted to store a hash of the Permalink instead of the URL, you can use the following:

Expand All @@ -109,6 +43,4 @@ Since XMLImporter 2.1, the `prepareImportValue` function will choose the first m

## Advanced Tips

- The `{$root}` parameter can used in your source URL which will be evaluated at run time to the value of the Symphony constant URL, eg. `{$root}/feed/news/` becomes `http://example.com/feed/news/`
- By default Symphony will set the timeout for retrieving the source URL to be 60 seconds. This can be updated by modifying the `timeout` setting in your saved XML Importer file which are located in `/workspace/xml-importers/`.

By default Symphony will set the timeout for retrieving the source URL to be 60 seconds. This can be updated by modifying the `timeout` setting in your saved XML Importer file which are located in `/workspace/xml-importers/`.

0 comments on commit 084930f

Please sign in to comment.