Specifying xml parsing with multiple roots having the same name using etree -



Specifying xml parsing with multiple roots having the same name using etree -

i'm using xml.etree.elementtree parse xml file in form-

<element> <status>ok</status> <duration> <value>340110</value> <text>3 jours 22 heures</text> </duration> <distance> <value>1734542</value> <text>1 735 km</text> </distance> </element>

i separating out time values , comparing them smallest possible value. however, i'm not sure how without ending getting distance value, messes dataset. code have far fetching under values root-

import xml.etree.elementtree et times=[] in htmlsource: root=et.fromstring(i) value in root.iter('value'): times.append(value.text)

is there way can modify values under duration , not distance? give thanks in advance.

i managed figure 1 out. needed maintain index of values true original data, hard because time status of element changed there no 'value' portion , index of next values bumped absence. solution both problem , original one.

for in htmlsource: root=et.fromstring(i) #parses info element in root.iter('element'): if element[0].text == 'ok' temp=element[1][0].text #finds time value times.append(temp) #adds time value list else: times.append(0)

the element[1][0] indicates first 'child' of sec root of element specified, needed value root, , .text gives me text contents of root. element[0] status, first root under element.

xml parsing xml-parsing elementtree xml.etree

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -