Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > parsing OPML

Reply
Thread Tools

parsing OPML

 
 
Chris
Guest
Posts: n/a
 
      04-06-2004
I am trying to write a script that will parse my Bloglines OPML export
(see snippet below) and output an HTML blogroll.

I can get at all the actual blog entries with the code below. But the
problem is that I would like to get at the "folder" level ("Test and
Demo" and "Unfiled" below) which just has a name and no other
attributes so that I can group the entries in their "categories"
something like this (http://rpc.bloglines.com/blogroll?html=1&id=chrislott).
My code only lists the entries themselves...

********************************blogs.opml**
<opml version="1.0">
<head>
<title>Bloglines Subscriptions</title>
<dateCreated>Sun, 4 Apr 2004 20:15:17 GMT</dateCreated>
<ownerEmail></ownerEmail>
</head>
<body>
<outline title="Subscriptions">
<outline title="Test and Demo">
<outline title="del.icio.us/imao/Learning"
htmlUrl="http://del.icio.us/imao/Learning" type="rss"
xmlUrl="http://del.icio.us/rss/imao/Learning"/>

<outline title="Fairbanks, Alaska Weather"
htmlUrl="http://www.rssweather.com/hw3.php?zipcode=99701" type="rss"
xmlUrl="http://rssweather.com/rss.php?hwvUT=F&hwvUP=in&hwvUS=mph&hwvUV=mi&hwvCCC hange=forecast&hwvSF=Y&maxdays=2&daysonly=2&hwvSty le=ce&hwvTTL=60&place=fairbanks&state=ak&zipcode=9 9701&country=us&county=02090&zone=AKZ222&alt=rss20 a"/>
</outline>

<outline title="Unfiled">

<outline title="Boxes and Arrows"
htmlUrl="http://www.boxesandarrows.com/" type="rss"
xmlUrl="http://www.boxesandarrows.com/index.xml"/>
<outline title="CBB Plagiarism Project -"
htmlUrl="http://leeds.bates.edu/cbb/" type="rss"
xmlUrl="http://leeds.bates.edu/cbb/module.php?mod=node&op=feed"/>

</outline>


********************************************my script**

from xml.sax import make_parser
from xml.sax.handler import ContentHandler

class OPMLHandler(ContentHandler):

def startElement(self, name, attrs):
if name == 'outline':
self.title = attrs.get('title', '')
self.url = attrs.get('xmlUrl', '')

def endElement(self, name):
if name == 'outline':
print self.level, ':', self.title, '-', self.url

parser = make_parser()
curHandler = OPMLHandler()
parser.setContentHandler(curHandler)
parser.parse(open('blogs.opml'))
 
Reply With Quote
 
 
 
 
Richard Morse
Guest
Posts: n/a
 
      04-07-2004
In article < >,
(Chris) wrote:

> I am trying to write a script that will parse my Bloglines OPML export
> (see snippet below) and output an HTML blogroll.

[snip]
> from xml.sax import make_parser
> from xml.sax.handler import ContentHandler
>
> class OPMLHandler(ContentHandler):
>
> def startElement(self, name, attrs):
> if name == 'outline':
> self.title = attrs.get('title', '')
> self.url = attrs.get('xmlUrl', '')
>
> def endElement(self, name):
> if name == 'outline':
> print self.level, ':', self.title, '-', self.url
>
> parser = make_parser()
> curHandler = OPMLHandler()
> parser.setContentHandler(curHandler)
> parser.parse(open('blogs.opml'))


It looks to me like this is Python.

This is a Perl newsgroup.

Perhaps you meant to post to a Python newsgroup?

Ricky

--
Pukku
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OPML help required ebeneke@telkomsa.net XML 0 02-22-2007 08:43 AM
How to convert XML file to OPML File ... Tom Denford Computer Support 1 04-24-2005 01:26 PM
How to convert XML file to OPML File ... Tom Denford XML 0 04-22-2005 07:05 PM
trying to apply CSS to DOM/OPML Kate XML 1 02-11-2004 05:53 PM
How to convert XML subscription file to OPML Desi XML 1 02-02-2004 01:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57