python - Parsing XML with Identical Keys and Attribute Names -
i'm working api outputs xml same <fl> key , uses same attribute name:
<response uri="/webaddress/"> <result> <quotes> <row no="1"> <fl val="id">12345</fl> <fl val="number"> <![cdata[ 12346 ]]> </fl> <fl val="subject"> <![cdata[ test ]]> </fl> <fl val="stage"> <![cdata[ draft ]]> </fl> <fl val="valid till"> <![cdata[ 2016-01-23 ]]> </fl> <fl val="contactid">12121</fl> i'm sure can still work it, i'm pretty new , i'm struggling find examples apply. i'm working in python 3.5 xml.etree don't care library i'm working with.
could offer example of how content out of element given particular name-value attribute pair, i.e. store '12345' or '12346' variable?
the documentation gives examples along explanation. example:
import xml.etree.elementtree et tree = et.parse('data.xml') root = tree.getroot() fl in root.iter('fl'): val = fl.attrib['val'] text = fl.text.strip() print("the %s %s" % (val, text))
Comments
Post a Comment