Robert Citek wrote:

> You're too kind.  And thanks for the rubypodder code.  However, I 
> think I might need to understand a bit more about xml.  So I looked 
> at the original bashpodder.shell script and noticed that it used 
> xsltproc.  So I created a stripped-down version of the original 
> script to extract the url names from one podcast rss:
>

Yes, I wondered about the sed call to get the url as well. If the
<item><enclosure url=""> is the only occurance of the 'url' string, then
I guess you are safe. But, if url occurs in some text or if there is a
latter tag (image, link) that has a url attribute, you could get errors.
So why did the xsltproc go away, since it is a good way to execute the
XPath expression : <apply-templates select="/rss/channel/item/enclosure"/>
for all the enclosures?

> #!/bin/bash
> { cat<<"eof"
> <?xml version="1.0"?>
> <stylesheet version="1.0"
>         xmlns="http://www.w3.org/1999/XSL/Transform";>
>         <output method="text"/>
>         <template match="/">
>                 <apply-templates select="/rss/channel/item/enclosure"/>
>         </template>
>         <template match="enclosure">
>                 <value-of select="@url"/><text>&#10;</text>
>         </template>
> </stylesheet>
> eof
> } > parse_enclosure.xsl
>
> wget -q http://radio.weblogs.com/0142912/categories/bluegrassexpress/
> rss.xml -O - |
> xsltproc parse_enclosure.xsl -
>
>
> Now I've got an excuse to learn xsl, too.  :)  I figure I'll take the 
> above script and convert it to ruby.  That should be good practice.
>
Good luck with that. At the moment, XSL support for Ruby is not well
defined*. Check my latest del.icio.us tags for more on this. Doing this
will get you more involved with external Ruby libs, sort of like using
CPAN, but harder.

However, just to be clear. The existing rubypodder is parsing the RSS
xml for you and turning them into regular ruby collections of classes.
So it becomes trivial:

RSS::Parser.parse(rss_xml_string, false).items.each {|item| puts 
item.enclosure.url}

No need to understand RSS, xml or xsl. BTW, this is true of the REXML** package 
when applied to any 
XML input, not just RSS. And REXML does XPath just fine, so you don't really 
need XSL unless you have a big reformatting job. 

So, I recently had to import some date from (strange, legacy) XML into MySQL. I 
had a XSLT stylesheet, but I converted it easily 
into REXML. E.g. The "Ruby Way" to do the above parsing

xml = REXML::Document.new(File.open(xml_filename))
xml.elements.each("/rss/channel/item/enclosure") do |enclosure|
   puts enclosure.attribute("url")
end

Compared to XSLT, easier on the eyes, no?

* This is rumoured to change in 2.0. In the meantime, you can use the sablotron 
binding for XSLT.
  Some (myself) think that the XPATH support in REXML is enough for most 
things. 
** REXML = Ruby Std library component to generate/parse XML.

Ed

> Regards,
> - Robert
> http://www.cwelug.org/downloads
> Help others get OpenSource software.  Distribute FLOSS
> for Windows, Linux, *BSD, and MacOS X with BitTorrent
>
>
> _______________________________________________
> CWE-LUG mailing list
> [email protected]
> http://www.cwelug.org/
> http://www.cwelug.org/archives/
> http://www.cwelug.org/mailinglist/


-- 
Ed Howland
WDT Solutions, LLC.
[EMAIL PROTECTED]
(314) 962-0766

 
_______________________________________________
CWE-LUG mailing list
[email protected]
http://www.cwelug.org/
http://www.cwelug.org/archives/
http://www.cwelug.org/mailinglist/

Reply via email to