1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #! python3
# coding: utf-8
from termcolor import cprint
import xml.etree.ElementTree as ET
XML = '''<?xml version='1.0' ?>
<list>
<CLIP title="test">
<GROUP title="Media Info">
<FIELD title="Duration" value="26 mins " />
<FIELD title="Duration (short)" value="26m" />
<FIELD title="Duration (no frames)" value="26 mins " />
<FIELD title="Duration (TC)" value="00:26:00:00" />
<FIELD title="Framerate" value="25" />
<mode>auto</mode>
<langue>francais</langue>
</GROUP>
<GROUP title="AAF info">
<FIELD title="Content type" value="Composition" />
<FIELD title="Total video edits" value="1" />
<FIELD title="Total audio tracks" value="2" />
</GROUP>
<GROUP title="File Info">
<FIELD title="password" value="" />
<FIELD title="username" value="" />
</GROUP>
</CLIP>
</list>'''
root = ET.fromstring(XML)
for child in root[0]: # CLIP
cprint('''child tag = {}, child attribut = {}'''.format(child.tag, child.attrib), 'green')
'''
child tag = GROUP, child attribut = {'title': 'Media Info'}
child tag = GROUP, child attribut = {'title': 'AAF info'}
child tag = GROUP, child attribut = {'title': 'File Info'}
'''
for child in root[0][0]: # GROUP
cprint('''child tag = {}, child attribut = {}'''.format(child.tag, child.attrib), 'green')
'''
child tag = FIELD, child attribut = {'title': 'Duration', 'value': '26 mins '}
child tag = FIELD, child attribut = {'title': 'Duration (short)', 'value': '26m'}
child tag = FIELD, child attribut = {'title': 'Duration (no frames)', 'value': '26 mins '}
child tag = FIELD, child attribut = {'title': 'Duration (TC)', 'value': '00:26:00:00'}
child tag = FIELD, child attribut = {'title': 'Framerate', 'value': '25'}
child tag = mode, child attribut = {}
child tag = langue, child attribut = {}
'''
attribut_dict = root[0][0][0].attrib
for key, value in attribut_dict.items():
cprint('''key = {}, value = {}'''.format(key, value), 'cyan')
'''
key = title, value = Duration
key = value, value = 26 mins
'''
cprint(root[0][0][0].attrib['value'], 'red') # 26 mins |
Partager