Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-deepxml循环文件_Python_Xml_Elementtree - Fatal编程技术网

Python-deepxml循环文件

Python-deepxml循环文件,python,xml,elementtree,Python,Xml,Elementtree,我正在处理一个XML文件,它看起来像下面的代码,真实的文件有很多spreekbeurt会话,但我让它可读。我的目标是从所有的spreekbeurt课程中获得voorvoegsel和achternaam部分的文本 此代码打印: {'nieuw': 'nee'} {'nieuw': 'ja'} {'nieuw': 'nee'} {'nieuw': 'nee'} 但是我怎样才能把孩子们从狂欢节上打印出来呢 提前谢谢 您可以使用find() >>> for spreekbeurt i

我正在处理一个XML文件,它看起来像下面的代码,真实的文件有很多spreekbeurt会话,但我让它可读。我的目标是从所有的spreekbeurt课程中获得voorvoegsel和achternaam部分的文本

此代码打印:

{'nieuw': 'nee'}
{'nieuw': 'ja'}
{'nieuw': 'nee'}
{'nieuw': 'nee'}
但是我怎样才能把孩子们从狂欢节上打印出来呢

提前谢谢

您可以使用
find()

>>> for spreekbeurt in root.iter('spreekbeurt'):
...     v = spreekbeurt.find('spreker/voorvoegsels')
...     a = spreekbeurt.find('spreker/naam/achternaam')
...     print v.text, a.text
...
De heer Marcouch
*)事实上,它不仅支持简单路径,还支持表达式

{'nieuw': 'nee'}
{'nieuw': 'ja'}
{'nieuw': 'nee'}
{'nieuw': 'nee'}
>>> for spreekbeurt in root.iter('spreekbeurt'):
...     v = spreekbeurt.find('spreker/voorvoegsels')
...     a = spreekbeurt.find('spreker/naam/achternaam')
...     print v.text, a.text
...
De heer Marcouch