lundi 20 juin 2016

Read all XML files under multiple directories using python


I am using Pandas through Jupyter Notebooks. I have 10 XML files which are stored in multiple locations. For example:

./A/1.xml
./A/2.xml
./A/3.xml
./B/4.xml
./B/5.xml
./B/6.xml

How can I load all of these files so that I can extract three particular elements in each file such as id, name and hypothesis?

I need help in the loading aspect of the question. FYI the path used above works if I do the following for each file:

from lxml import etree
ltree = etree.parse("./100/A/1.xml")

I would prefer a solution using BeautifulSoup however lxml or ElementTree is fine too.


Aucun commentaire:

Enregistrer un commentaire