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


Groups > comp.lang.python > #82599

Re: xml SAX Parsing in python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'else:': 0.03; 'value,': 0.04; 'tree': 0.05; 'element': 0.07; 'none:': 0.07; 'parser': 0.07; 'parsed': 0.09; 'parsing': 0.09; 'subject:xml': 0.09; 'python': 0.11; 'def': 0.12; 'wrote': 0.14; 'once.': 0.16; 'tag,': 0.16; 'subject:python': 0.16; 'skip:= 10': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'memory': 0.22; 'own.': 0.24; 'parse': 0.24; '&gt;': 0.26; 'define': 0.26; 'shown': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'xml': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'class': 0.32; 'this.': 0.32; 'text': 0.33; '(e.g.': 0.33; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'convert': 0.35; 'received:google.com': 0.35; '8bit%:9': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'structure': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'skip:\xc2 10': 0.60; 'new': 0.61; "you're": 0.61; 'below.': 0.71
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=imztu/3iAKST1Lfc/TbxcmV/mCC7OVXqgHPF0JBqunQ=; b=GRpn4fwIeuEvzG2y1Bty9b4X6RkL/GMMW/ZR+Bn+c0yRXPXztShc0gGYaJEFB6XqK3 LjvGaTN0WuncH/TnyR7uypurQogPMsV5rYZtwqxH+nfUS5uvAZex1uG5nBfHM0oRdu8C Ch6IaXqSoRuRAblvixYRgeIi0TlMVdzwd51+uZWf5JNrydAgYh49XULZigGnKlyDyq1j IDaq2B69Lyr8lFvSDZTrPLYf7kaMKDfzQ2AsYhnffP26ipIN0HxTdo3Uhesx1ixt39Cz xHYxe6LZBDLNQ/ELmx4XG6HWk0QyYAuOhD4B5AetNhEAqeAsRz7Tb+7tHe4BizPGcJzE TxCw==
X-Received by 10.70.129.233 with SMTP id nz9mr71915427pdb.114.1418834408979; Wed, 17 Dec 2014 08:40:08 -0800 (PST)
MIME-Version 1.0
In-Reply-To <1562125511.108039.1418797814530.JavaMail.yahoo@jws10606.mail.bf1.yahoo.com>
References <1562125511.108039.1418797814530.JavaMail.yahoo@jws10606.mail.bf1.yahoo.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 17 Dec 2014 09:39:28 -0700
Subject Re: xml SAX Parsing in python
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=001a11c336b2f14275050a6c20c6
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17008.1418834418.18130.python-list@python.org> (permalink)
Lines 89
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418834418 news.xs4all.nl 2971 [2001:888:2000:d::a6]:46777
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82599

Show key headers only | 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