<taskListNextID= "62292"><TaskModule= "Reliability"owner= "Vprovodi"ID= "59074"Status= "Error"result= "XFL is ok;init OK; Tests:17, expected failures:1, unexpected:1, Actual total count is ok:17 >= (unmatched!); ADB OK; crashlogs:0; tombstones:1; sigs:2+2+0+0; throttlings:0+0+0+0; Device errors:0 "Addedby= "[Email protected]{client}"Changedby= "[Email protected]{client}"Runningby= "LAB_LABRQABJ"Runningon= "Host007-agent11"Addedtime= "1410503955947"StartTime= "1410581427467"Finishtime= "1410591199376" > <Match Property= "Android.build.origin"value= "ABT"/> <Match Property= "Android.build.target"value= "KK"/> <Match Property= "Android.build.branch"value= "Art-opt"/> <Match Property= "Android.build.date"value= "WW36"/> <Match Property= "Android.build.type"value= "Userdebug"/> <Match Property= "Android.device.type"value= "T100ta"/> <Match Property= "Agent.group"value= "Art-opt"/> < Propertyname= "Vm.backend"value= "Bronze"/> < Propertyname= "Task.group"value= "Weekly_ww36_abt_art-opt_bronze_t100ta"/> < Propertyname= "Vm.mode"value= "Art"/> < Propertyname= "Task.tests"value= "ZIP_VM"/></Task></taskList>
Parsing using Python's unique etree approach
1 fromXml.etreeImportElementTree as et2 3 defParsexml (filename=". \\resource\\test.xml"}):4Result_list = []5Tree =et.parse (filename)6Root =tree.getroot ()7 8elements = Root.findall ("Task")9 forElinchelements:TenAdict = {} Oneattr = El.attrib#attributes of Task node AAdict.update (attr)#attr is a dict, put the key-values of attr into Adict -Matches = El.findall ('Match') - forMinchmatches: theKey = M.attrib.get (' Property') -Value = M.attrib.get ('value') -Adict[key] =value -Props = El.findall (' Property') + forPinchProps: -Key = P.attrib.get ('name') +Value = P.attrib.get ('value') AAdict[key] =value at ifIs_target (adict, filter): - result_list.append (adict) - returnResult_list
Using Minidom parsing
1 fromXml.dom.minidomImportParse2 3 defload_task_list (filename):4Xml_dom =Parse (filename)5Node_tasklist =xml_dom.documentelement6 7 forNode_taskinchNode_tasklist.getelementsbytagname ('Task'):8 for(Attr_name, Attr_value)inchNode_task.attributes.items ():9 PrintAttr_name, Attr_value#attributes of Task nodeTen forNodeinchNode_task.childnodes: One ifNode.nodetype = =node. Element_node: A ifNode.nodename = ='Match': -Prop_name = Node.getattribute (' Property') -Prop_value = Node.getattribute ('value') the Print 'match:%s:%s'%(Prop_name, Prop_value) - elifNode.nodename = =' Property': -Prop_name = Node.getattribute ('name') -Prop_value = Node.getattribute ('value') + Print 'Property :%s:%s'%(Prop_name, Prop_value) - +Load_task_list (R'. \resource\test.xml')
Python parsing xml