The limit tag only restricts number of entries in the data feed and won’t take into the account of any custom condition. What you need is to take the whole feed and apply condition in your own code.
This can be done but this will require some PHP knowledges.
In your template, enable ‘Allow PHP’ and set ‘PHP Parsing Stage’ to OUTPUT (Templates->Template Management->Preferences). And apply similar code as follow:
<h1>W3C XML Conditional Limit Test with PHP Codes</h1>
<?
/* PHP initialization */
$count=0;
?>
Show only the first two food items in the data feed that contain over 800 calories.<br><br>
{exp:ano_xml_parser:fetch source='http://www.w3schools.com/xml/simple.xml' refresh="0" parent_tag="breakfast_menu" child_tag="food"}
<?
/* PHP section within ANO XML parser loop, make sure PHP is enabled and PHP Parsing Stage is set to OUTPUT in the template */
if ( {food_calories}>800) {
$count++;
if ($count<=2) {
echo "Food #".$count.": {food_name} has {food_calories} calories.<br>";
echo "<hr>";
}
}
?>
{/exp:ano_xml_parser:fetch}
This is tricky since all tags will be parsed as child nodes during XML parsing stage.
If your feed only contains tag, you may try to hack the module as follow:
Open up the file mod.ano_xml_parser.php and add the following two lines around line 127 after this statement:
$code = curl_exec($c);
/* ADD the following two lines to strip out html tags */
$code=str_replace("", "", $code);
$code=str_replace("", "", $code);
Follow this fashion to strip more tags if necessary. Not pretty but should fit your need.
Ah, I totally misinterpreted your original question.
May be this will work for you:
<h1>XML no child tag test</h1>
{exp:ano_xml_parser:fetch source='http://peteryoungren.org/blog_xml' refresh='0' limit='0' parent_tag='blog' child_tag='entry'}
Title: {entry_title}<br>
URL title: {entry_url_title}
<hr>
{if entry_title_2}
Title: {entry_title_2}<br>
URL title: {entry_url_title_2}
<hr>
{/if}
{if entry_title_3}
Title: {entry_title_3}<br>
URL title: {entry_url_title_3}
<hr>
{/if}
{/exp:ano_xml_parser:fetch}
This module is a life-saver. Literally saving our project from the brink of despair (Blip.tv decided to deny our completely straightforward broadcast design videos, even though we are paying customers).
Thank you for this!
Question: In this SmugMug RSS feed, I need the image inside the <description> tag, it is the thumbnail for the video:
http://api.smugmug.com/hack/feed.mg?Type=gallery&Data=9733284_4AABX&format=rss
I am able to get the description tag in its entirety. I am also able to strip out the “PARAGRAPH” tags by adding that hack to line 127. But I am not able to return that IMG tag alone, the thumbnail for the video.
Help?
{exp:ano_xml_parser:fetch source='http://api.smugmug.com/hack/feed.mg?Type=gallery&Data=9733284_4AABX&format=rss' refresh='0' parent_tag='channel' child_tag='item'}
<video>
<title><![CDATA[{item_title}]]></title>
<thumbnail>{item_description_img}</thumbnail>
<url><![CDATA[{item_guid}]]></url>
</video>
{/exp:ano_xml_parser:fetch}
I see more and more people want to extract data from the feed. You can do that in the template level if you know a bit of PHP and regular expression. First you need to enable “Allow PHP” and set “PHP Parsing Stage” to Output in the Template Preference section for the template that you are working on.
You can always use Google to find the right regular expression as I did below to figure out the right expression:
{exp:ano_xml_parser:fetch source='http://api.smugmug.com/hack/feed.mg?Type=gallery&Data=9733284_4AABX&format=rss' refresh='0' parent_tag='channel' child_tag='item'}
Title:{item_title}<br>
<?php
$description = '{item_description}';
$regex = '/<img[^>]*>/Ui';
if (preg_match($regex, $description, $regs)) {
$img = $regs[0];
echo "Thumbnail=".$img."
";
}
?>
Published Date:{item_pubDate}
<hr>
{/exp:ano_xml_parser:fetch}
Thanks so much! That’s the ticket.
For any other SmugMug users out there, here is the XML template Arnold helped me make, scraping movie and custom thumbnail from a SmugMug RSS…
{exp:ano_xml_parser:fetch source='http://api.smugmug.com/hack/feed.mg?Type=gallery&Data=9733284_4AABX&format=rss' refresh='0' parent_tag='channel' child_tag='item'}
<video>
<title><![CDATA[{item_title}]]></title>
<media><![CDATA[{item_guid}]]></media>
<?php
$description = '{item_description}';
$imgtag = '/<img.*jpg/Ui';
$imgurl = '/http.*jpg/';
if (preg_match($imgtag, $description, $imgtagresult)) {
preg_match($imgurl, $imgtagresult[0], $imgurlresult);
$img = $imgurlresult[0];
echo "<thumb><![CDATA[" . $img . "]]></thumb>";
}
?>
</video>
{/exp:ano_xml_parser:fetch}
This is a great forum.
Thanks again.
x
hi arnold,
i am trying to use php substr() to remove a few characters from a variable coming from my xml and i am having a hard time. can you look at my code and let me know what’s wrong with it?
{exp:ano_xml_parser:fetch source='http://api.happenstand.com/v1/events/start?api_key=6cb3d6c6ad54b77d7f43743f9d72b1212017e568175a7b10301b7ba1b5f1bcb8&loc=1&date=2009-10-30&format=xml' refresh='0' parent_tag='events' child_tag='event'}
<div class="event">
<h4>{event_name}</h4>
<h5>{event_places}</h5>
<h5>
<?php
$eventstart='{event_start}';
echo substr($eventstart, 0, -6);
?>
</h5>
</div>
{/exp:ano_xml_parser:fetch}
the problem is that “echo $eventstart;” prints the contents of the variable (which look something like this “2009-09-25 00:00:0”) while “echo substr($eventstart, 0, -6); ” prints the name of the variable (which looks like this “{event_”).
Thanks!!!
St
Hi There,
Just to clarify my previous post: Arnold’s fast responses were extremely helpful when I was stuck using this module, but he didn’t actually write the code for me, I used his example to construct my own solution.
I found this link really helpful in figuring out PHP Regular Expressions:
http://www.regular-expressions.info/php.html
If you follow the examples above, you would ‘Match’ the string you are looking for (instead of ‘Substring-ing’ for the date)
Here are two examples of PHP ‘Match’-ing that illustrate what I mean…
<?php
if (preg_match("/ell/", "Hello World!", $word)) {
echo "Match was found
";
echo $word[0];
}
if (preg_match("/\d{4,4}-\d{2,2}-\d{2,2}/", "1999-03-12", $number)) {
echo "Match was found
";
echo $number[0];
}
?>
Hope that helps!
x
<?php
$time ='{event_start}';
if (preg_match("/[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]/", $time, $stuff)) {
echo $stuff[0];
}
?>
the code above works! obviously not the most intelligent pattern match… but it works. thanks!
do you know what the best way to unpack a variable (that’s part of the xml loop) into a php array and then access that array on a next page (after a reload) is?
thanks.
st
I’m finding that conditionals just aren’t working.
{exp:ano_xml_parser:fetch source='http://api.smugmug.com/hack/feed.mg?Type=gallery&Data=10145677_gXk2L&format=atom03&ImageCount=100&Sandboxed=1' refresh='0' parent_tag='feed' child_tag='entry' limit='999'}
{if entry_title=="video"}
<video source="{entry_id}" thumbnail="{exp:trimmer stop_before="-"}{entry_id}{/exp:trimmer}-Ti-2.jpg" link="" title="{exp:trimmer start_after="video"}{entry_title}{/exp:trimmer}" />
{if:else}
<image source="{exp:trimmer stop_before="-"}{entry_id}{/exp:trimmer}-M.jpg" thumbnail="{exp:trimmer stop_before="-"}{entry_id}{/exp:trimmer}-Ti-2.jpg" link="" title="{exp:trimmer start_after="photo"}{entry_title}{/exp:trimmer}" >
{/if}
{/exp:ano_xml_parser:fetch}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.