Apr-30-2018, 07:49 PM
Hi.
I'm trying to use Python (3.6.5) and lxml to iterate through an existing XML file.
I would like to take the XML file's opening tag names and create a folder based on the XML structure and tag name.
So, for example, if the XML file contained the following:
C:\FolderA
C:\FolderA\FolderB
C:\FolderA\FolderC
C:\FolderA\FolderC\FolderD
C:\FolderA\FolderE
The first thing I'm doing is loading the xml file and then parse through using 'interparse' :
Any suggestions would be appreciated.
Thanks.
I'm trying to use Python (3.6.5) and lxml to iterate through an existing XML file.
I would like to take the XML file's opening tag names and create a folder based on the XML structure and tag name.
So, for example, if the XML file contained the following:
<FolderA> <FolderB> </FolderB> <FolderC> <FolderD> </FolderD> </FolderC> <FolderE> </FolderE> </FolderA>then I would like to create the following folders:
C:\FolderA
C:\FolderA\FolderB
C:\FolderA\FolderC
C:\FolderA\FolderC\FolderD
C:\FolderA\FolderE
The first thing I'm doing is loading the xml file and then parse through using 'interparse' :
tree = etree.xmlfile(xml) context = etree.iterparse(tree)When I run this, however, I'm getting a 'TypeError: expected str, bytes, or os.PathLike object, not lxml.etree.xmlfile'. Any suggestions on what I need to be doing differently to now iterate through the tags and create the folders?
Any suggestions would be appreciated.
Thanks.