FEED43 (Feed For Free)

Understanding Search Patterns and Output Templates

Search patterns are used to extract snippets of text or HTML from source documents. Search patterns can be treated as regular expressions, yet very easy to understand and write.

Output templates are used to join these snippets together to form user-friendly content of feed's items.

Here is the simple example that describes this idea.

Let's say, we need to create a feed that reports current weather, and have found a web page with the following source code:

...
<html>
...
...[content goes here]...
...

<body>
...
...[content goes here]...
...

<h1>Weather in Washington</h1>
...
...[content goes here]...
...

<div class="content">
UV Index: 1 Low<br/>
Wind: From SSE at 9 mph<br/>
Humidity: 69%<br/>
Pressure: 30.02 in.<br/>
Dew Point: 46&deg;F<br/>
Visibility: 10.0 miles<br/>
</div>
...
...[content goes here]...
...

</body>
</html>

We can create the following search pattern:

<h1>{%}</h1>{*}<div class="content">{%}</div>
This means: take everything between <h1> and </h1> as a first snippet (which can be referred as {%1} in output template), then take everything between <div class="content"> and </div> as a second snippet (referred as {%2}).

If we apply this pattern to the above html source, we will get the following list of snippets:

{%1} = Weather in Washington
{%2} = UV Index: 1 Low<br/> Wind: From SSE at 9 mph<br/> Humidity: 69%<br/> Pressure: 30.02 in.<br/> Dew Point: 46&deg;F<br/> Visibility: 10.0 miles<br/>

Now we can define output template, which combines these snippets together:

<b>{%1}</b><br/>{%2}
Here {%1} is substituted with the first snippet, and {%2} — with the second.

Thus, we get the resulting html code:

<b>Weather in Washington</b><br/>UV Index: 1 Low<br/> Wind: From SSE at 9 mph<br/> Humidity: 69%<br/> Pressure: 30.02 in.<br/> Dew Point: 46&deg;F<br/> Visibility: 10.0 miles<br/>