python - Prepending nightmare -
i wrote code connect filemaker server , ask new record created on backend server. portion works fine , result contains unexpected text not show in browser. couldn't find operations work looking @ tree in browser ended printing tags , attributes out , every tag attribute pair has format:
tag: {http://www.filemaker.com/xml/fmresultset}error attrib: {'code': '0'}
in code below i'm having put qualified tag code first find work. makes harder figure out xpath object want xml. second find below doesn't work since can't figure out path. path should /resultset/record/ , attribute record-id. have idea of happening. why fmresultset document prepended every tag?
url = self.getbaseurl( machineid, file, lay ) + fields + "&-new" result = self.sendurl( url ) import xml.etree.elementtree et root = et.fromstring(result) self.printxml( root ) base = "{http://www.filemaker.com/xml/fmresultset}" find = root.find( base + "error" ) error = find.attrib[ 'code' ] recid = 0 if ( error == '0' ): find = root.find( base + "resultset" + base + "/record" ) recid = find.attrib[ 'record-id' ]
keith
ok... mentioned word namespace , figured out. uses element version of root.
def getxmlvalue( self, root, path, value ): ns = {'fmrs': 'http://www.filemaker.com/xml/fmresultset' } find = root.find( path, ns ) value = find.attrib[ value ] return value def geterror ( self, root ): return self.getxmlvalue ( root, "fmrs:error", 'code' ) def getrecid ( self, root ): return self.getxmlvalue ( root, "fmrs:resultset/fmrs:record", 'record-id' )
this code correctly returns correct value. expecting like. create instance of class call setnamespace(). i'm having put these references fmrs rather not solves issues , code isn't horrible read.
thanks assist.
-keith
Comments
Post a Comment