FAQ
I am trying to parse an XML file using Python and found this resource
http://diveintopython.org/xml_processing/parsing_xml.html

But I didn't even get past the second line... it does not see the xml file? But it is there.
from xml.dom import minidom >>> xmldoc = minidom.parse('~/Desktop/test/test.xml')
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
xmldoc = minidom.parse('~/Desktop/test/test.xml')
File "C:\Program Files\python26\lib\xml\dom\minidom.py", line 1918, in parse
return expatbuilder.parse(file)
File "C:\Program Files\python26\lib\xml\dom\expatbuilder.py", line 922, in parse
fp = open(file, 'rb')
IOError: [Errno 2] No such file or directory: '~/Desktop/test/test.xml'
>>>


Lukas


________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090314/a0d99d4d/attachment.htm>

Search Discussions

  • Lukas Agrapidis at Mar 14, 2009 at 10:47 pm
    Sorry please ignore... I changed the path to c:\temp\test.xml and it worked just fine.
    I'm sure I'll have some questions when I actually start playing with it though.


    Lukas


    ________________________________





    ________________________________
    From: Lukas Agrapidis <lagrapidis at yahoo.com>
    To: tutor at python.org
    Sent: Saturday, March 14, 2009 6:30:35 PM
    Subject: [Tutor] Parse XML file


    I am trying to parse an XML file using Python and found this resource
    http://diveintopython.org/xml_processing/parsing_xml.html

    But I didn't even get past the second line... it does not see the xml file? But it is there.
    from xml.dom import minidom >>> xmldoc = minidom.parse('~/Desktop/test/test.xml')
    Traceback (most recent call last):
    File "<pyshell#7>", line 1, in <module>
    xmldoc = minidom.parse('~/Desktop/test/test.xml')
    File "C:\Program Files\python26\lib\xml\dom\minidom.py", line 1918, in parse
    return expatbuilder.parse(file)
    File "C:\Program Files\python26\lib\xml\dom\expatbuilder.py", line 922, in parse
    fp = open(file, 'rb')
    IOError: [Errno 2] No such file or directory: '~/Desktop/test/test.xml'
    >>>


    Lukas


    ________________________________
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/tutor/attachments/20090314/3871a9f2/attachment-0001.htm>
  • Stefan Behnel at Mar 15, 2009 at 9:56 am

    Lukas Agrapidis wrote:
    I am trying to parse an XML file using Python and found this resource
    http://diveintopython.org/xml_processing/parsing_xml.html
    You might be interested in ElementTree:

    http://effbot.org/zone/element.htm

    It's a lot easier to use than minidom, especially for new users. It's
    available in the standard library as "xml.etree.ElementTree" module since
    Python 2.5.

    Stefan
  • Marc at Mar 15, 2009 at 3:25 pm

    Message: 5
    Date: Sun, 15 Mar 2009 10:56:22 +0100
    From: Stefan Behnel <stefan_ml at behnel.de>
    Subject: Re: [Tutor] Parse XML file
    To: tutor at python.org
    Message-ID: <gpijc7$6uo$1 at ger.gmane.org>
    Content-Type: text/plain; charset=ISO-8859-1

    Lukas Agrapidis wrote:
    I am trying to parse an XML file using Python and found this resource
    http://diveintopython.org/xml_processing/parsing_xml.html
    You might be interested in ElementTree:

    http://effbot.org/zone/element.htm

    It's a lot easier to use than minidom, especially for new users. It's
    available in the standard library as "xml.etree.ElementTree" module
    since
    Python 2.5.
    I would agree - I was struggling with minidom, Stefan recommended
    ElementTree and another person (deleted the email and can't recall his
    name) recommended lxml. I was able to get a working understanding of
    these libraries in less than an hour and solve the problems I had
    encountered with minidom in a very short time. (BTW, parsing xml was
    probably a poor choice for my first project while learning Python, but
    then again, nobody has ever accused me of making my life easy)

    Marc

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedMar 14, '09 at 10:30p
activeMar 15, '09 at 3:25p
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase