Showing posts with label xpath. Show all posts
Showing posts with label xpath. Show all posts

Sunday, December 24, 2006

some simple XML (opml) parsing in Python

Say you have an opml file, whose filename is stored in the variable "filename":

from xml.dom import minidom
xmldoc = minidom.parse(filename)

"""
Print all the feed urls in the file
"""

for x in xmldoc.getElementsByTagName('outline'):
   if x.attribute.has_key('xmlUrl'):
      print(x.attributes["xmlUrl"].value)

Where your opml doc probably looks like:

<opml>
   <head>
      <title>Title for document</title>
   </head>
   <body>
      <outline text="somerssfeedtext" title="somerssfeedtitle" htmlUrl="urltofeedssite" xmlUrl="urltofeed">
      ...
      ... (more outline elements)
   </body>
</opml>

For more xml/python goodness look here.

If you want to use xpath/xml/python, look here.