Skip to content

Instantly share code, notes, and snippets.

@Janderson
Last active April 22, 2022 21:43
Show Gist options
  • Select an option

  • Save Janderson/8e63ab7d7e361082898cda3f184a92b5 to your computer and use it in GitHub Desktop.

Select an option

Save Janderson/8e63ab7d7e361082898cda3f184a92b5 to your computer and use it in GitHub Desktop.
XMind 8 to csv
import xml.etree.ElementTree as xmlET
import pandas as pd
import click
from zipfile import ZipFile
@click.group()
def cli():
pass
@cli.command("tocsv")
@click.argument("filename")
def cmd(filename):
read_zip(filename)
def read_zip(filename):
with ZipFile(filename) as myzip:
with myzip.open('content.xml') as xml_file:
read_xml(filename, xml_file.read())
def read_xml(filename, data):
xml = xmlET.fromstring(data)
items = []
for it in xml.iter():
item = {
"text": it.text,
"tag": it.tag
}
items.append(item)
df = pd.DataFrame(items)
df["filename"] = filename
df.to_csv(f"{filename}.csv")
print("done")
if __name__ == "__main__":
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment