Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-03-31 22:29:49

duchamp
Member
From: Patagonia
Registered: 2005-02-03
Posts: 222
Website

Questions about parsing XML

I’m trying to parse this > Yahoo Weather with a little modification of the tcm_rss plugin.
The Plugin parses very well the contents of that feed but I would like to capture some specific data:

like city, region, country, temperature, etc.

What’s the trouble?

I don’t know how to parse (or capture) data included in a tag like this one:

<code><yweather:location city=“Puerto Madryn” region=”“ country=“AR”/></code>

The plugin uses MagpieRSS and, for example, to parse this:

<code><description>Yahoo! Weather for Puerto Madryn, AR</description></code>

and insert it into the excerpt I can use something like this:

<code>if($rss->channel[‘description’])
{
$out[“excerpt”] = $rss->channel[‘description’];
}</code><br />

Allright, how I access the city data?

Thx in advance!

Offline

#2 2006-04-01 00:48:08

akokskis
Plugin Author
From: Baltimore-ish, USofA
Registered: 2004-11-28
Posts: 230
Website

Re: Questions about parsing XML

You’d need to use some regex (regular expressions). I’d help you out, but I’m not well versed in regex (read: I don’t know regex).

But uhm, the basics would be to find the string “<code><yweather:location … /></code>” and then, within that string find the <code>city=”…”</code> and take out that “…” part. As to how you’d actually go about doing that, I wish I could tell you, but as I’ve said, I don’t really know regex.


My Photoblog, and my personal site. Got nav? ako_nav.
Thanks for taking the time to look…

— vc3 —

Offline

#3 2006-04-01 01:00:07

KurtRaschke
Plugin Author
Registered: 2004-05-16
Posts: 275

Re: Questions about parsing XML

A regex-based parser is the hard way. Look at the PHP XML parsing functions and in particular SimpleXML if you are willing to be constrained to PHP 5.

-Kurt


kurt@kurtraschke.com

Offline

#4 2006-04-01 01:21:51

akokskis
Plugin Author
From: Baltimore-ish, USofA
Registered: 2004-11-28
Posts: 230
Website

Re: Questions about parsing XML

Whoa, never knew about those functions. Neat stuff. Seems like that is tons easier than trying to regex it all…


My Photoblog, and my personal site. Got nav? ako_nav.
Thanks for taking the time to look…

— vc3 —

Offline

#5 2006-04-01 13:04:51

duchamp
Member
From: Patagonia
Registered: 2005-02-03
Posts: 222
Website

Re: Questions about parsing XML

Thx Im going to take a view right now …

Offline

Board footer

Powered by FluxBB