Is there a way to convert XML to SQL INSERT using the command line, here is examples:
<something>
<somthingelse>lol</somethingelse>
</something>
would be
INSERT INTO `database` (`something`)
VALUES
(lol)
Or something like that.
Is there a way to convert XML to SQL INSERT using the command line, here is examples:
<something>
<somthingelse>lol</somethingelse>
</something>
would be
INSERT INTO `database` (`something`)
VALUES
(lol)
Or something like that.
With xmllint using libxml version 20708:
Name of root node "something": xmllint --xpath "name()" file.xml
Text "lol": xmllint --xpath "//*/*/text()" file.xml
Script sql.sh:
#!/bin/bash
file="$1"
table=$(xmllint --xpath "name()" "$file")
value=$(xmllint --xpath "//*/*/text()" "$file")
cat << EOF
INSERT INTO \`${table}\`
VALUES
(${value})
EOF
$ ./sql.sh file.xml
Output:
INSERT INTO `something`
VALUES
(lol)