parsing XML

Martin v. Loewis martin at v.loewis.de
Fri May 14 17:46:25 EDT 2010


>>> Hi to all, let's say we have the following Xml
>>> <team>
>>>    <player name='Mick Fowler' age='27' height='1.96m'>
>>>      <points>17.1</points>
>>>      <rebounds>6.4</rebounds>
>>>    </player>
>>>    <player name='Ivan Ivanovic' age='29' height='2.04m'>
>>>      <points>15.5</points>
>>>      <rebounds>7.8</rebounds>
>>>    </player>
>>> </team>
>>>
>>> How can i get the players name, age and height?
>>> DOM or SAX and how
>>
>> Homework?
> 
> I would hope that every school teacher who teaches Python is able to
> skip through c.l.py and the python-tutor list before accepting a
> homework result.

If he uses your proposed solution, it probably wouldn't pass, anyway,
because it's neither DOM nor SAX. If he's really interested in a
solution to the original problem, then ElementTree is fine, of course.

As for teachers scanning relevant forums: that's often impractical.
For example, for an XML lecture, choice of programming language may be
to the student. You then have to search web forums, mailing lists, and
newsgroups for Java, Python, C#, Ruby, Scala, plus StackOverflow.

Solutions copied from the net often show a level of cuteness beyond
what you'd expect from a student (like your solution: who'd be using
reflection to access three attributes?). So you rather take these clues
as the starting point for an investigation (and then hope that Google
comes up with the specific source code).

Of course, it may also be that getting help is explicitly allowed.

Regards,
Martin



More information about the Python-list mailing list