parsing OPML

Discussion in 'Perl Misc' started by Chris, Apr 6, 2004.

  1. Chris

    Chris Guest

    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&hwvCCChange=forecast&hwvSF=Y&maxdays=2&daysonly=2&hwvStyle=ce&hwvTTL=60&place=fairbanks&state=ak&zipcode=99701&country=us&county=02090&zone=AKZ222&alt=rss20a"/>
    </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'))
    Chris, Apr 6, 2004
    #1
    1. Advertising

  2. 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
    Richard Morse, Apr 7, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Desi
    Replies:
    1
    Views:
    646
    Klaus Johannes Rusch
    Feb 2, 2004
  2. Kate
    Replies:
    1
    Views:
    580
    Martin Honnen
    Feb 11, 2004
  3. Tom Denford
    Replies:
    0
    Views:
    638
    Tom Denford
    Apr 22, 2005
  4. OPML help required

    , Feb 22, 2007, in forum: XML
    Replies:
    0
    Views:
    424
  5. Muness Alrubaie

    RubyConf Coverage by OPML

    Muness Alrubaie, Oct 15, 2005, in forum: Ruby
    Replies:
    2
    Views:
    103
    James Britt
    Oct 15, 2005
Loading...

Share This Page