[Tutor] trying to parse an xml file

Felix Dietrich felix.dietrich at sperrhaken.name
Sat Dec 14 18:30:00 CET 2013


bruce <badouglas at gmail.com> writes:

> Looking at a file -->>
> http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml>
>
> However, when I use elementtree:
>
>   document = ElementTree.parse( '/apps/parseapp2/testxml.xml' )
>
> I get an invalid error : not well-formed (invalid token):
>
> Anyone have any python suggestions as to how to proceed to parse out
> the data!

I skimmed the xml.etree.ElementTree documentation and tried the
following:

--------------------

from urllib.request import urlopen
import xml.etree.ElementTree as ET

URL = 'http://www.marquette.edu/mucentral/registrar/snapshot/fall13/xml/BIOL_bysubject.xml'

with urlopen(URL) as page:
    root = ET.fromstring(page.read())

print(next(root.iter('datetime')).text)

--------------------

Output: 12/14/2013 at 3:30 am

It worked as expected.  Maybe something is wrong with your local copy of
the xml-file.

--
Felix Dietrich


More information about the Tutor mailing list