XML-SAX parser problem
hitesh thakkar
hiteshthakkar.h at gmail.com
Tue Mar 11 13:53:29 EDT 2008
Hello,
Can any one help for error in following code.
actually i want to map parent element with child element, but i am unable to
do so.
here is the code which i am trying for please do reply if iam not on right
track.
import xml.sax.handler
class BookHandler(xml.sax.handler.ContentHandler):
def __init__(self):
self.inTitle1 = 0
self.inTitle2 = 0
self.mapping1 = {}
self.mapping2 = {}
def startElement(self, name, attributes="NULL"):
#attributes="None"
if name == "emph3":
self.buffer1 = ""
self.inTitle1 = 1
# self.id = attributes["None"]
elif name == "year":
self.buffer2 = ""
self.inTitle2 = 1
def characters(self,data):
if self.inTitle1 == 1:
self.buffer1 += data
elif self.inTitle2 == 1:
self.buffer2 += data
def endElement(self,name):
if name == "year":
self.inTitle2 = 0
self.mapping2[self.name] = self.buffer2
elif name =="emph3":
self.inTitle1 =0
self.mapping1[self.name] = self.buffer1
#<s>
#
# <emph3>Jose Joaquin Avila</emph3>
# <year>1929</year>
#
# <emph3>Yiye Avila</emph3>
# <year>1941</year>
#
#</s>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080311/950355a4/attachment.html>
More information about the Python-list
mailing list