RE: [Pythonmac-SIG] XML handler design

2005-04-04 Thread Henning.Ramm
>If you want a cleaner coder, you give might one of the more "pythonic" >XML APIs, like ElementTree or XIST a try. > >ElementTree: http://effbot.org/zone/element-index.htm >XIST: http://www.livinglogic.de/Python/xist/ Thank you for this links - lots of interesting stuff there that I didn't know.

Re: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Martina Oefelein
Hi Henning, My first attempt used DOM, but I get a cleaner, more readable, better extendable code with SAX. If you want a cleaner coder, you give might one of the more "pythonic" XML APIs, like ElementTree or XIST a try. ElementTree: http://effbot.org/zone/element-index.htm XIST: http://www.livin

Re: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Eric Nieuwland
<[EMAIL PROTECTED]> wrote: As you see my get methods aren't much more than redirections to the object's own methods - one could access them directly via MyHandler.pages[12] or MyHandler.pages,getSortedArray() Yes, I see it. What I tried to explain is that I use the factory pattern (well, sort of)

RE: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Henning.Ramm
def getPages(self): return self.pages.getSortedArray() def getPage(self, no): return self.pages[no] >My style is to create/build a data structure in the parser and have a >single get... method that will give me the result. >Your getPage/getPages would be part of t

RE: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Henning.Ramm
>> And where should the "output" go to? >> All examples use print statements in the element handlers. >I'm not certain we are clear. Instead of output statements you >store the data in some instance variable - in your case it appears >self.pages is your instance variable containing the data. Rig

Re: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Eric Nieuwland
<[EMAIL PROTECTED]> wrote: def startElement(self, name, attrs): self._queue.append(name) # keep the order of processed tags handler = str('_start_'+name) if hasattr(self, handler): self.__class__.__dict__[handler](self, attrs) Is there a better syntax for self.__class__.__dict_

RE: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Henning.Ramm
>> Is there a better syntax for self.__class__.__dict__[handler]? >how about: > handler = getattr(self, str('_start_'+name),None) ># fetch the actual bound method > if handler is not None: > handler( attrs ) That's good, I think. Thank you. >or so

Re: [Pythonmac-SIG] XML handler design

2005-03-24 Thread David Reed
On Mar 24, 2005, at 8:35 AM, [EMAIL PROTECTED] wrote: David Reed wrote: There's probably a better mailing list with XML parsing experts. I'm certainly not an expert but have done a little XML parsing. I've always followed the pattern of using startElement, characters and endElement to grab all the

Re: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Steve Spicklemire
Hi Henning, def startElement(self, name, attrs): self._queue.append(name) # keep the order of processed tags handler = str('_start_'+name) if hasattr(self, handler): self.__class__.__dict__[handler](self, attrs) Is there a better syntax for self.__class__.__dict__[handler]? ho

RE: [Pythonmac-SIG] XML handler design

2005-03-24 Thread Henning.Ramm
David Reed wrote: >There's probably a better mailing list with XML parsing experts. I'm >certainly not an expert but have done a little XML parsing. >I've always >followed the pattern of using startElement, characters and endElement >to grab all the data. In the startElement method you set a i

[Pythonmac-SIG] XML handler design

2005-03-24 Thread Henning.Ramm
Hi there! I just wrote a SAX handler for XML files that describe a newspaper issue (list of pages etc.); I'd like to know if I could do it better. def startElement(self, name, attrs): """call an own handler method named _start_Something for a Something element if it exists, to avoid