Textpattern Forum

You are not logged in. Register | Login | Help

#41 2010-03-12 20:41:54

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_xml : extract data from XML feeds

How can make one a list of his Top Last.fm albums when the XML response looks like this:

<topalbums user="RJ" type="overall">
  <album rank="1">
    <name>Images and Words</name>
    <playcount>174</playcount>
    <mbid>f20971f2-c8ad-4d26-91ab-730f6dedafb2</mbid>  
    <url>
      http://www.last.fm/music/Dream+Theater/Images+and+Words
    </url>
    <artist>
      <name>Dream Theater</name>
      <mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid>
      <url>http://www.last.fm/music/Dream+Theater</url>
    </artist>
    <image size="small">...</image>
    <image size="medium">...</image>
    <image size="large">...</image>
  </album>
</topalbums>

Everything works fine until I’m trying to parse the nested fields and the <image size="..."> fields. Could someone give me a hint how to acomplish this, please? please?

Otherwise, another great plugin, Stef! Makes me feel again like a programmer! ;-)

Offline

#42 2010-03-12 21:08:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,979
Website

Re: smd_xml : extract data from XML feeds

mapu wrote:

Everything works fine until I’m trying to parse the nested fields and the <image size="..."> fields.

I think you may need to wait until I’ve finished the nested rules portion of the code, sorry. I have a tentative version about 60% done, just been sidetracked the last few days.

Since lastfm are reusing things like name, mbid, and url you’ll need a version of the plugin that allows you to specify that you want fields="name, artist->name, artist->mbid" and so on. The plugin should be able to keep those separate so you can grab them separately from the feed. I’m also thinking about a way of allowing a shorthand so you don’t have to specify each and every sub-tag if you happen to want them all. Not sure if I can figure that out, but I’ll try.

I also need to be smarter with concatenation of like-named nodes. At the moment it doesn’t take attributes into account, but it should. Bad plugin *spank spank* no gruel for you…

Otherwise, another great plugin, Stef! Makes me feel again like a programmer! ;-)

Thanks, uhhh, I think ;-)

Last edited by Bloke (2010-03-12 21:09:23)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#43 2010-03-13 20:03:33

mapu
Member
From: Munich, Germany
Registered: 2004-03-16
Posts: 141

Re: smd_xml : extract data from XML feeds

Then I will wait patiently for the new version! ;-)

Offline

#44 2010-03-30 00:22:07

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 739

Re: smd_xml : extract data from XML feeds

Using Flickr API to get info back (due to limit on photos via RSS) … and having some issues with feed below

<rsp stat="ok">
<photos page="1" pages="1" perpage="500" total="109">
<photo id="444" owner="444" secret="444" server="2804" farm="3" title="Photo title" ispublic="1" isfriend="0" isfamily="0" ownername="Photo Owner Name" dateadded="1269854014" />
<photo id="555" owner="555" secret="444" server="2804" farm="3" title="Photo title" ispublic="1" isfriend="0" isfamily="0" ownername="Photo Owner Name" dateadded="1269854014" />

… etc …

</photos>
</rsp>

  • If I set attribute record as “photos” – I see one result (and replacement tags do nothing – i.e. don’t replace)
  • If I set attribute record as “photo” – I see 109 result (and replacement tags do nothing – i.e. don’t replace)

Is this data format not compatible with smd_xml due to the self-closing tags?

Offline

#45 2010-03-30 00:48:11

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 739

Re: smd_xml : extract data from XML feeds

UPDATE – by requesting “extras” from the Flickr API, I now get the following:

<photo id="666" owner="666" secret="666" server="2698" farm="3" title="summer" ispublic="1" isfriend="0" isfamily="0" ownername="Owner Name" dateadded="1269796453" license="0" dateupload="1269751696" datetaken="2010-03-21 12:24:50" datetakengranularity="0" iconserver="2761" iconfarm="3" lastupdate="1269774620" latitude="0" longitude="0" accuracy="0" tags="summer" machine_tags="" views="1">
<description>summer</description>
</photo>

setting attribute record to “photo”, I can extract {description} … but not the other metadata within the “photo” tag …

Offline

#46 2010-03-30 08:31:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,979
Website

Re: smd_xml : extract data from XML feeds

nardo wrote:

having some issues with feed

Hmmm, I tried setting the record to rsp as well and it still did nothing. It seems this isn’t a classical ‘record’ structure insofar as it’s just a list of self-closing tags with a tonne of attributes.

You’re right that smd_xml is a bit dim when it comes to self-closing tags. For reasons I have yet to uncover, the parser skips over them. I need to see if I can factor such tags into the new version.

You’ll get the same issues with the ‘extra’ data because the photo tag still doesn’t contain any text; just sub-tags. Again, I need to be smarter about how I capture such tags inside the plugin. Sorry.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#47 2010-04-19 13:24:16

jens31
Plugin Author
From: munich / dtschermani
Registered: 2008-08-25
Posts: 183
Website

Re: smd_xml : extract data from XML feeds

hii

thanks for this great(!!!!) plugin. makes live easy!!

but nevertheless, i have my issues ;)
is it possible to sort the output? i guess its now sorted by date, but it would be kool, to get it sorting by a ‘field’..?
possible?

Offline

#48 2010-04-19 14:08:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,979
Website

Re: smd_xml : extract data from XML feeds

jens31 wrote:

is it possible to sort the output?

Nope, sorry. I’m not sure if the plugin can perform a sort because all the data is parsed and reformatted on-the-fly by your plugin form/container. I can’t predict how you’re going to use these; I’d have to be some kind of demi-God to sort free-form information ;-)

i guess its now sorted by date

It’s sorted by the order of the incoming XML data (I presume it’s date in your case).

One thing you could try is to output the data in tabular format and offer your visitors the option to sort it themselves using one of the many jQuery table sorting plugins out there. Never used them myself, but it might be worth a shot.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#49 2010-05-23 02:28:12

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 739

Re: smd_xml : extract data from XML feeds

hey bloke, recently got a PHP error on my site (didn’t record at the time) but it was due to the data feed not being available (the server it was on was undergoing maintenance) – does the plugin have a way to die quietly if the data is not available?

(if it does, maybe there’s a more local reason for the error I got)

Offline

#50 2010-05-23 08:05:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,979
Website

Re: smd_xml : extract data from XML feeds

nardo wrote:

does the plugin have a way to die quietly if the data is not available?

Not explicitly but I set a timeout of 10 seconds in there so, in theory (it’s difficult to test) it’s supposed to give up after that length of time and return nothing. If I can find a way to verify this is actually working — by making a local feed and putting the site in maintenance mode for example — I’ll see what the plugin does. And if it falls over for whatever reason I’ll see what I can do to fix it. Thanks for bringing this to my attention.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB