Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82599

Re: xml SAX Parsing in python

References <1562125511.108039.1418797814530.JavaMail.yahoo@jws10606.mail.bf1.yahoo.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-12-17 09:39 -0700
Subject Re: xml SAX Parsing in python
Newsgroups comp.lang.python
Message-ID <mailman.17008.1418834418.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Dec 16, 2014 at 11:30 PM, Abubakar Roko
<abroko@yahoo.com.dmarc.invalid> wrote:
>
> Good day,
>
> Please I am new in using python to write program. I am trying to parse an
XML document using sax parse  and store the parsed result in a tree like
defined
> below. XNode class define an xml element which has an ID , a tag, a text
value, children element and a parent element
>
>                    class XNode(object):
>
>                             def __init__(self, ID ="", elmName="",
elmValue="", parent=None):
>
>                                  self.ID = ID
>                                  self.elmName=elmName
>                                  self.elmValue=elmValue
>                                  self.childs=[]
>                                 self.parent=parent
>
>
>                            def  getPath(self):
>                                   if self.parent is None:
>                                        return self.elmName
>                                  else:
>                                        return self.parent.getPath()+"/"+
self.elmName
>
> I  wrote a program that parse an XML document ,  convert the  document
 into the tree like structure defined above and then return the parsed
result to
> the program that call it.  The program shown below.

I'm not sure why you would want to use a SAX parser for this. The advantage
of incremental parsing is that you never have to have the whole document in
memory at once. If you use it to construct some DOM-like structure from the
document, then you're going to have the whole document in memory anyway,
and you might as well just use one of the existing implementations (e.g.
ElementTree) rather than reinventing your own.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: xml SAX Parsing in python Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-17 09:39 -0700

csiph-web