Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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.
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
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…
Offline
Re: Questions about parsing XML
Thx Im going to take a view right now …
Offline
Pages: 1