Convert SQLite database to XML

2019-07-17 01:23发布

问题:

Is there any way to convert a .sqlite file to XML?

There exist tools that convert from XML to SQLite, but does are there tools that convert the other way, too?

回答1:

After some experimentation, I found a converter solution using sqlite3:

#!/bin/bash
SFILE="$1"
[ ! -f "$SFILE" ] && echo "$SFILE doesn't exist" 2>&1 && exit 2
for i in $(sqlite3 "$SFILE" '.table'); do
    echo -e ".mode csv\nselect * from $i;" | sqlite3 "$SFILE" > "$i".csv
done

start the script with ./script database.sqlite

Creates for each table via sqlite3 database.sqlite '.table' a tableentry.csv file.

Now to convert csv to xml...