我有以下示例XML代码
<pathway>
<relation entry1="62" entry2="64" type="PPrel">
<subtype name="activation" value="-->"/>
</relation>
<relation entry1="54" entry2="55" type="PPrel">
<subtype name="activation" value="-->"/>
<subtype name="phosphorylation" value="+p"/>
</relation>
<relation entry1="55" entry2="82" type="PPrel">
<subtype name="activation" value="-->"/>
<subtype name="phosphorylation" value="+p"/>
</relation>
</pathway>我尝试将子类型排序到一个列表中,但如果条目有多个子类型,则将它们组合到一个字符串中
示例输出:‘激活’,‘激活;磷酸化’,‘激活;磷酸化’
我当前的代码是
tree= ET.parse('file.xml')
root= tree.getroot()
relation = []
for son in root:
for step_son in son:
if len(son.getchildren()) > 1:
relation.append(step_son.get('name'))
if len(son.getchildren()) < 2:
relation.append(step_son.get('name'))我对关系的输出是:
‘激活’,‘激活’,‘磷酸化’,‘激活’,‘磷酸化’
任何帮助都会令人惊叹,谢谢!
https://stackoverflow.com/questions/44554040
复制相似问题