# -*- coding: utf8 -*-

import xml.sax.handler



class SaxBaseHandler(xml.sax.handler.ContentHandler):

    def __init__(self):
        self._value = ""
        xml.sax.handler.ContentHandler.__init__(self)

    def startElement(self, name, attrs):
        # remove potential namespace prefixes
        name=name.split(":")[-1]
        attrs2={}
        for k,v in attrs.items():
            k=k.split(":")[-1]
            attrs2[k]=v
        self._value = ''
        return (name, attrs2)

    def endElement(self, name):
        # remove potential namespace prefixes
        name=name.split(":")[-1]
        self._value = self._value.strip()
        return name

    # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    def characters(self, ch):
        self._value += ch
