Monday, 15 March 2010

Attribute error in python while parsing an XML -



Attribute error in python while parsing an XML -

i kinda new python. working on project parses xml in python , python code :

class="lang-python prettyprint-override">from xml.dom import minidom re-create import re-create class xmlparse: def __init__(self, xmlfile): self = minidom.parse(xmlfile) def findadress(self): itemlist =self.getelementsbytagname('addresses') homecoming itemlist[0].attributes['firstname'].value if __name__ == '__main__': open("sample.xml") f: parse = xmlparse(f) print parse.findadress()

but when run code output error:

attributeerror: xmlparse instance has no attribute 'findadress'

and findadress function spelled correctly in main, reason ever getting error.

any help appreciated.

and wanted know, how can validate xml xsd schema in python?

"self = minidom.parse(xmlfile)" overwrites xmlparse object created. want assign xml doc variable instead:

from xml.dom import minidom re-create import re-create class xmlparse: def __init__(self, xmlfile): self.doc = minidom.parse(xmlfile) def findadress(self): itemlist =self.doc.getelementsbytagname('addresses') homecoming itemlist[0].attributes['firstname'].value

python xml xml-parsing

No comments:

Post a Comment