>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.
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
<[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)
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
>> 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
<[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_
>> 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
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
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
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
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
11 matches
Mail list logo