FAQ
Sorry , I didn't follow the format of posting to the group. Well I am new to
xml and python . What I basically want to do is to read elements from the
xml which is by the way large ~2GB and read the attributes and make a
decision as to whether i want to keep that element or not . I am told that
xml.sax is good for reading a large xml file because it can read from a
stream but what about writing the xml file back Thank you for your help.
On Wed, Oct 22, 2008 at 1:49 PM, Alan Gauld wrote:

"amit sethi" <amit.pureenergy at gmail.com> wrote

Please, always use a meaningful subject line when posting!
and do not reply to an existing thread, changing the subject.
These things mess up threaded reading tools such as gmane
and newsreaders. This reduces your chances of a reply.

Hi can any body give me an example as to how i can use Incremental Parser
in
xml.sax
If you look in the XML Topic Guide section of the Python web site there
is a full tutorial on using SAX. This is a good starting point:

http://pyxml.sourceforge.net/topics/docs.html

But frankly I'd strongly advise you to look at ElementTree if you are
parsing XML. Its much easier to use. The only time I'd use sax nowadays
is if I was porting code from some other sax based solution.

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

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


--
A-M-I-T S|S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081022/e21b7a5b/attachment.htm>

Search Discussions

  • A.T.Hofkamp at Oct 22, 2008 at 1:17 pm

    amit sethi wrote:
    Sorry , I didn't follow the format of posting to the group. Well I am new to
    xml and python . What I basically want to do is to read elements from the
    xml which is by the way large ~2GB and read the attributes and make a
    decision as to whether i want to keep that element or not . I am told that
    xml.sax is good for reading a large xml file because it can read from a
    stream but what about writing the xml file back Thank you for your help.
    In general, we help with Python problems rather writing applications for free.

    You 'll either have to start paying somebody to do the work for you (in which
    case this is the wrong place to ask), or you'll have to make your hands dirty,
    and start reading/learning/coding/experimenting to solve your problem.


    When you get stuck, you can ask how to overcome that obstacle (usually by
    scaling the problem down to a small example), and we will try to find an answer.


    Sincerely,
    Albert
  • Kent Johnson at Oct 22, 2008 at 2:25 pm

    On Wed, Oct 22, 2008 at 9:07 AM, amit sethi wrote:
    Sorry , I didn't follow the format of posting to the group. Well I am new to
    xml and python . What I basically want to do is to read elements from the
    xml which is by the way large ~2GB and read the attributes and make a
    decision as to whether i want to keep that element or not . I am told that
    xml.sax is good for reading a large xml file because it can read from a
    stream but what about writing the xml file back Thank you for your help.
    The iterparse() method of ElementTree might be useful, it allows you
    to prune the parsed tree as it is built:
    http://effbot.org/zone/element-iterparse.htm

    The resulting tree can be written back to a file using the write() method:
    http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm#elementtree.ElementTree.ElementTree.write-method

    Kent

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouptutor @
categoriespython
postedOct 22, '08 at 1:07p
activeOct 22, '08 at 2:25p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase