Sax Handler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Juliano Freitas

    #1

    Sax Handler

    hello!!!

    here is my pythn code that's handle a xml file:

    =============== =============== =============== =============== =
    from xml.sax import saxutils, saxlib, saxexts, parseString

    class swdbHandler(sax lib.DocumentHan dler):
    def __init__(self):
    self.flag = 0

    def startElement(se lf, name, atts):
    if name == "swml":
    print "enter"

    def endElement(self , name):
    if name == "swml":
    print "exit"

    parser = saxexts.make_pa rser()
    parser.setDocum entHandler(swdb Handler())

    # here
    parser.parseFil e(open("exemplo .xml"))
    =============== =============== =============== =============== =

    i want to parse a "xml string" not a file how can i pass my swdbHandler
    to this string?? with parseString? i try but doesnt work?
    somebody can help me with this??

    Juliano Freitas

  • Mike Meyer

    #2
    Re: Sax Handler

    Juliano Freitas <jubafre@atlas. ucpel.tche.br> writes:
    [color=blue]
    > hello!!!
    >
    > here is my pythn code that's handle a xml file:
    >
    > =============== =============== =============== =============== =
    > from xml.sax import saxutils, saxlib, saxexts, parseString
    >
    > class swdbHandler(sax lib.DocumentHan dler):
    > def __init__(self):
    > self.flag = 0
    >
    > def startElement(se lf, name, atts):
    > if name == "swml":
    > print "enter"
    >
    > def endElement(self , name):
    > if name == "swml":
    > print "exit"
    >
    > parser = saxexts.make_pa rser()
    > parser.setDocum entHandler(swdb Handler())
    >
    > # here
    > parser.parseFil e(open("exemplo .xml"))
    > =============== =============== =============== =============== =
    >
    > i want to parse a "xml string" not a file how can i pass my swdbHandler
    > to this string?? with parseString? i try but doesnt work?
    > somebody can help me with this??[/color]

    Try the StringIO module. That will give you a file-like object for a string.

    <mike
    --
    Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

    Comment

    Working...