Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-12 14:19:00

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

XML Feeds

On my companies website we use the built in Textpattern Atom feed to allow people to subscribe to news and blog articles. My boss recently decided to commission a developer to design IOS and Android apps that will use the Atom feeds to display content.

During a meeting today with the developer he explained that the feeds generated by Textpattern weren’t working correctly with the apps. While testing on an Android tablet I noticed that the app was displaying portions of HTML code in places and not rendering content such as JS slideshows correctly, though it was displaying text and images. On an iPhone the app refused to display any content beyond the articles title and a broken image link.

The developer said that he needed a pure XML feed rather than Atom or RSS in order for the apps to work. I’m completely new to feeds having only set them up using Textpatterns tags. Does anyone have any advise on the best way to proceed? If this is something I can accomplish natively with Textpattern or via a plugin all the better.

—Edit—
Actually it appears I’m using RSS not Atom. While digging through my code to remind myself how I’d set things up I came across this txp:feed_link flavor="rss"

Last edited by Algaris (2012-09-12 14:48:41)

Offline

#2 2012-09-12 14:52:33

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: XML Feeds

I’d say rah_external_output is handy to output content as XML, but you’ll have to create the feed yourself. Could you provide some example of XML feed read by IOS?

Offline

#3 2012-09-12 15:03:23

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: XML Feeds

Thanks Oleg. I don’t have a feed to hand but I’ll see If I can find one tonight. Do you have any advice on creating XML feeds? I’m googling stuff at the moment but not having a lot of luck so far.

Offline

#4 2012-09-12 15:18:19

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: XML Feeds

I’d ask the app developer what they want the format to be.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2012-09-12 15:31:56

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: XML Feeds

Here is an example of rah_eo XML snippet. It’s not really difficult, but one has to care about wrapping some parts in CDATA. For jQuery-based slideshows, the feed should at least include some <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> tag, which it doesn’t. A working example would really help here.

Offline

#6 2012-09-12 15:46:38

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: XML Feeds

I found this guide to be a useful primer How to Create an Atom Feed”. It’s better than the official documents, I think. It’s not too difficult to work out suitable TXP tags to call the required information using the templates contained in it.

PS. Just noticed Oleg provides a link to my form based on the template in his post above.

Last edited by joebaich (2012-09-12 15:51:26)

Offline

#7 2012-09-13 14:57:09

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: XML Feeds

Thank you everyone for your advice and links. I’m working my way through all the information at the moment. I’ve managed to get an example of a feed that works correctly from the app developer.

http://freedom-apps.com/funny-math/jokes.xml

Offline

#8 2012-09-13 16:11:51

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: XML Feeds

Not quite valid XML for me (lacks namespaces), but you can try to mimic it with the following rah_eo_feed form:

; Content-type: text/xml
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
 <title><txp:site_name /></title>
 <description><txp:site_slogan /></description>
 <link><txp:site_url /></link>
 <docs><txp:site_url /></docs>
 <lastBuildDate><txp:php>echo safe_strftime('rfc822');</txp:php></lastBuildDate>
 <pubDate><txp:php>echo safe_strftime('rfc822');</txp:php></pubDate>
 <generator>http://textpattern.com/</generator>

 <txp:article_custom>
   <item>
     <title><txp:title no_widow="0" /></title>
     <description><![CDATA[<txp:excerpt />]]></description>
     <guid isPermaLink="false"><txp:permlink /></guid>
     <pubDate><txp:posted  format="rfc822" /></pubDate>
   </item>
 </txp:article_custom>

</channel>
</rss>

There is very little chance though that javascript will work.

Last edited by etc (2012-09-13 16:17:18)

Offline

#9 2012-09-27 10:53:05

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: XML Feeds

Thank you so much for your help. I’ve got the code partially working, the main problem is when a full article is opened in a news reader or a web browser the incorrect article is displayed. In this case it always displays the oldest article. Otherwise everything else works, the feed displays the correct title, article image and excerpt without any problem.

; Content-type: text/xml
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><txp:site_name /> » Boarders Blog</title>
		<description>Weekly Boarders Blog</description>
		<txp:article_custom section="boarders-blog">
			<link><txp:permlink /></link>
			<docs><txp:permlink /></docs>
		</txp:article_custom>
		<lastBuildDate><txp:php>echo safe_strftime('rfc822');</txp:php></lastBuildDate>
		<pubDate><txp:php>echo safe_strftime('rfc822');</txp:php></pubDate>
		<generator>http://textpattern.com/</generator>
		<txp:article_custom section="boarders-blog">
			<item>
				<title><txp:section title="1"/> » <txp:title no_widow="0" /></title>
				<description><![CDATA[<txp:article_image /><txp:excerpt />]]></description>
				<guid isPermaLink="false"><txp:permlink /></guid>
				<pubDate><txp:posted  format="rfc822" /></pubDate>
			</item>
		</txp:article_custom>
	</channel>
</rss>

I suppect the issue lies with this part of the code.

<txp:article_custom section="boarders-blog">
	<link><txp:permlink /></link>
	<docs><txp:permlink /></docs>
</txp:article_custom>

Offline

#10 2012-09-27 14:36:26

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: XML Feeds

Hi Ross, could you precise what you mean by “full article is opened in a news reader or a web browser”? Your rss contains no visible (in my browser) links, how do you open an article?

Anyway, what is the purpose of the first article_custom block? My knowledge of rss specs is close to null, but I think <channel> should contain only one top-level <link>, and you output 10 of them. Should not they rather be inside <item>:

<txp:article_custom section="boarders-blog">
	<item>
		<title><txp:permlink><txp:section title="1"/> » <txp:title no_widow="0" /></txp:permlink></title>
		<description><![CDATA[<txp:article_image /><txp:excerpt />]]></description>
		<guid isPermaLink="false"><txp:permlink /></guid>
		<pubDate><txp:posted  format="rfc822" /></pubDate>
	</item>
</txp:article_custom>

Offline

#11 2012-09-27 14:44:27

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 553

Re: XML Feeds

etc wrote:

Hi Ross, could you precise what you mean by “full article is opened in a news reader or a web browser”? Your rss contains no visible (in my browser) links, how do you open an article?

I loaded the feed into a News Reader which displayed each articles title in a list. Single clicking the articles title the news reader shows the excerpt. Double clicking the articles title opens a tab in the news reader (or Safari if set in the preferences) and displays it on the website. When I open an article in a new tab the link always points to the first article in the section rather than the one who’s exert I was viewing.

Offline

#12 2012-09-27 14:56:08

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: XML Feeds

What if you replace the first article_custom block by just

<link><txp:site_url /></link>
<docs><txp:site_url /></docs>

and the second one by

<txp:article_custom section="boarders-blog">
	<item>
		<title><txp:section title="1"/> » <txp:title no_widow="0" /></title>
		<link><txp:permlink /></link>
		<description><![CDATA[<txp:article_image /><txp:excerpt />]]></description>
		<guid isPermaLink="false"><txp:permlink /></guid>
		<pubDate><txp:posted  format="rfc822" /></pubDate>
	</item>
</txp:article_custom>

I have no Safari at hand to test, sorry.

Offline

Board footer

Powered by FluxBB