View Single Post
Old 05-20-2009, 11:42 AM   #6
gwynevans
Wizzard
gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.
 
gwynevans's Avatar
 
Posts: 1,402
Karma: 2000000
Join Date: Nov 2007
Location: UK
Device: iPad 2, iPhone 6s, Kindle Voyage & Kindle PaperWhite
For the XML in Python, I've found BeautifulSoup to be easy to get started with.

('>>>' is the python command prompt when it's run interactively)
e.g.
Code:
>>> from BeautifulSoup import BeautifulStoneSoup
>>> file = open('example.xml')  # your example above with a </entry> appended
>>> soup = BeautifulStoneSoup(file)
>>> soup.title.string
u'The Shadow of the Lion'
>>> soup.findAll('author')
[<author>Lackey, Mercedes</author>, <author>Flint, Eric</author>, <author>Freer, Dave</author>]
>>> soup.findAll('author')[0].string
u'Lackey, Mercedes'
>>> keywords = soup.keywords
>>> keywords.findAll('keyword')
[<keyword>Historical fiction</keyword>, <keyword>Fantasy fiction</keyword>, <keyword>16th century</keyword>, <keyword>Science fiction</keyword>]
>>> [k.string for k in keywords.findAll('keyword')]
[u'Historical fiction', u'Fantasy fiction', u'16th century', u'Science fiction']
>>>
gwynevans is offline   Reply With Quote