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


Groups > comp.lang.python > #82599 > unrolled thread

Re: xml SAX Parsing in python

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2014-12-17 09:39 -0700
Last post2014-12-17 09:39 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#82599 — Re: xml SAX Parsing in python

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-12-17 09:39 -0700
SubjectRe: xml SAX Parsing in python
Message-ID<mailman.17008.1418834418.18130.python-list@python.org>

[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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web