Answer the question
In order to leave comments, you need to log in
XML Mapper for Python
Good afternoon,
Recently there was a problem with XML parsing, and I wanted it to be convenient.
I would like to be able to use it like this:
class RaceMapper(XMLMapper):
"""Example usage
"""
time = XMLAttrib(attrib='time')
date = XMLAttrib(attrib='date')
title = XMLAttrib(xpath='Title')
eligibility = XMLAttrib(xpath='Eligibility', attrib='type')
if __name__ == '__main__:
tree = etree.fromstring(open(xml_file_path).read())
race = RaceMapper(tree.find('.//Race'))
print race.date, race.time, race.title, race.eligibility
<Race id="187505" date="20080414" time="1410+0100" raceType="Hurdle" >
<Title>Parklands Golf For All Conditionals' Novices' Handicap Hdl</Title>
<Eligibility type="4YO plus"/>
<Distance units="yards" value="5280" text="3m 0f 0y"/>
</Race>
Answer the question
In order to leave comments, you need to log in
Why reinvent XPath/XSLT if they already exist?
Or did I not understand something?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question