Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2012-09-27 14:56:17

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

Re: XML Feeds

etc wrote:

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>

Chances are I’m doing it wrong with the first article_custom block. At first my code looked like this:

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

but I found that every time I tried to open an article in my news reader it would send me to the websites homepage and not display the article. When I changed it to:

<txp:article_custom section=“boarders-blog” limit=“9999999”>
<link><txp:permlink /></link>
<docs><txp:permlink /></docs>
</txp:article_custom>

opening an article sent me to the correct section but displayed the wrong article.

Last edited by Algaris (2012-09-27 15:00:59)

Offline

#14 2012-09-27 15:00:47

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

Re: XML Feeds

Oleg. Thank you so much! That fixed it.

Offline

#15 2012-09-27 15:02:36

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

Re: XML Feeds

Glad it did! (but still missing what is wrong with the built-in txp rss feed)

Offline

#16 2012-09-28 12:59:24

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

Re: XML Feeds

I’ve just recived a reply from the app developer:

I just managed to get hold of your XML (via cURL) and see the following:

<title>Blog » Episode 34</title>
<link>http://www.example.com/blog/episode-34</link>
<description><![CDATA[<img src="http://www.example.com/images/633.jpg" alt="" width="766" height="280" />

Images need to be attached to the feed in the form media:thumbnail for the iOS XML parser framework to be able to read them. This means you literally provide the image URL, no information for how to display it such as width, height or alternative text.

Last edited by Algaris (2012-10-01 10:09:13)

Offline

#17 2012-09-28 16:01:14

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: XML Feeds

So, the structure he is looking for is? There isn’t set structure you need to follow or provide to some “framework”, so what is the exact structure he wants? iOS XML parser framework? Does he mean the general NSXMLParser class (or something else?), which is just a general XML parser which can parse any type of XML document. Granted, the images shouldn’t be embed to HTML if they are going to be used in the application.

You can generate needed markup using the images tag. Bonus is that it can support multiple image and generate lists. For instance:

<txp:if_article_image>
	<txp:images wraptag="media" break="thumbnail" class=""><txp:image_url/></txp:images>
</txp:if_article_image>

The above generates:

<media>
	<thumbnail>http://example.com/images/1.png</thumbnail>
	<thumbnail>http://example.com/images/5.png</thumbnail>
	<thumbnail>http://example.com/images/5.png</thumbnail>
</media>

Where all the images are associated with the article.

Or:

<txp:if_article_image>
	<txp:images wraptag="" break="media" class="">
		<thumbnail><txp:image_url/></thumbnail>
	</txp:images>
</txp:if_article_image>

Which generates:

<media>
	<thumbnail>http://example.com/images/1.png</thumbnail>
</media>
<media>
	<thumbnail>http://example.com/images/5.jpg</thumbnail>
</media>

Or:

<txp:images break="">
	<media:thumbnail><txp:image_url/><media:thumbnail>
</txp:images>

Which generates:

<media:thumbnail>http://example.com/images/1.png<media:thumbnail>

Some of those might be that instructed media:thumbnail he is looking for. Not sure if he means namespaces or nested structures. As far as the body content goes as whole, he most likely wants plain text. Otherwise he needs to render the HTML (not the best thing ever unless you want to build a generic feedreader), or hack the structure with a XML parser (not ideal either).

Offline

#18 2012-09-28 21:18:02

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

Re: XML Feeds

I’d bet on option 3, put inside <item>. And I second Jukka in that the app dev should provide you with some formal specs.

Edit: from what I’ve seen in the example feed, this should be

<txp:images break="">
	<media:thumbnail url='<txp:image_url />' />
</txp:images>

Last edited by etc (2012-09-29 08:37:30)

Offline

#19 2012-10-01 08:59:54

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

Re: XML Feeds

Thank you both for your replies and help. Until recently I’d never heard of iOS XML parser framework or the NSXMLParser class. When dealing with feeds I’ve always used the built in Textpattern tags and I’ve never had a problem before now, so all of this is very new to me and a little like flying in the dark.

I’ll run through your code and let you know how I get on.

Offline

#20 2012-12-03 09:53:38

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

Re: XML Feeds

Thank you all again for your help. I’ve managed to move things forward a lot because of it. It’s still on going but I’ve managed to get some more information from the app developer.

I’m using a customised framework which I wrote in a separate class to keep it separate which relies on one of their [Apple’s] APIs. I’ve included a screenshot of frameworks I’m using – non of them have specific RSS functionality, although parsing is included in Foundation I think.

The idea we briefly discussed on the phone does fix the problem – and I’ve figured out why from the Apple API documentation. Basically, the API takes the feed and extracts all elements from it with tags around it. It disposes of elements with tags not used (also, the scrollable text view does not support HTML tags – I’d have to use a WebView which can not be passed NSData, so the app would have to dynamically generate an HTML page every time and then load it in the WebView, which would be a very complex way of doing it!). Basically, it works if the only thing between the description tags is raw text.

Is it at-all possible to make it so when it generates the XML feed it runs a ‘Find and Replace’ to remove all items inside tags within the description tags?

Within the description tags I’m using the following code:

<description><![CDATA[<txp:article_image /><txp:body />]]></description>

When using <txp:body /> is there a way to strip out the HTML I’ve used to format my body text? For reference I’ve included my entire feed below.

; 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>
		<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 section="boarders-blog" limit="99999999999">
			<item>
				<title><txp:section title="1"/> » <txp:title no_widow="0" /></title>
				<link><txp:permlink /></link>
				<txp:if_article_image>
					<txp:images break="">
						<media:thumbnail url='<txp:image_url thumbnail="1" />' />
					</txp:images>
				</txp:if_article_image>
				<description><![CDATA[<txp:article_image /><txp:body />]]></description>
				<guid isPermaLink="false"><txp:permlink /></guid>
				<pubDate><txp:posted  format="rfc822" /></pubDate>
			</item>
		</txp:article_custom>
	</channel>
</rss>

Offline

#21 2012-12-03 11:37:06

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

Re: XML Feeds

Try to replace <txp:body /> with <txp:rah_function call="strip_tags"><txp:body /></txp:rah_function>.

Offline

#22 2012-12-03 11:58:40

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

Re: XML Feeds

Thanks Oleg. That does does the trick stripping out the tags. Hopefully the app will now work.

Offline

#23 2012-12-03 14:00:01

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

Re: XML Feeds

Just mind that tags text will not be removed, so <script>alert("hi")</script> will become alert("hi"). So, if you use script (form, video, audio, …) tags in articles, it might be better idea to remove them completely, replacing <txp:body /> with

<txp:etc_query data='<txp:body />' replace="//script|//form|//audio|//video">{//text()}</txp:etc_query>

Offline

Board footer

Powered by FluxBB