def create(doc_path, output_path="sqlite://"):
'''
Parse the relational table-like XML file provided by http://www.unimod.org/downloads.html
and convert each <tag>_row into an equivalent database entry.
By default the table will be held in memory.
'''
tree = preprocess_xml(doc_path)
engine = create_engine(output_path)
Base.metadata.create_all(engine)
session = sessionmaker(bind=engine, autoflush=False)()
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
for model in Base._decl_class_registry.values():
if hasattr(model, "_tag_name") and hasattr(model, "from_tag"):
for tag in tree.iterfind(".//" + model._tag_name):
session.add(model.from_tag(tag))
session.commit()
return session
评论列表
文章目录