用java写不胜其烦,得连接数据库,得用jdom转换XML文件,用Shell写只有下面几行:
# /usr/local/bin/mysql2xml
TMP_FILE=tmp.txt
RESULT_FILE=slot.xml
mysql -uroot -p1983228 -e"use ontology; select d.DB_Owner, a.DB_Tab,
a.DB_Attr, b.SlotName, b.SlotID, c.NodeName, c.NodeID from slot_db a,
slot b, node c,
db_info d where a.SlotID=b.SlotID and a.NodeID=c.NodeID and
a.DB_ID=d.DB_ID order by d.DB_Owner, DB_Tab;"
--default-character-set=utf8 > $TMP_FILE
# 删除字段名称
sed -i '1d' $TMP_FILE
awk 'BEGIN{print "<Slot_DB>"}
{print " <Item>"}
{print " <DB_Owner>",$1,"</DB_Owner>"}
{print " <DB_Tab>", $2,"</DB_Tab>"}
{print " <DB_Attr>", $3,"</DB_Attr>"}
{print " <SlotName>",$4,"</SlotName>"}
{print " <SlotID>", $5,"</SlotID>"}
{print " <NodeName>",$6,"</NodeName>"}
{print " <NodeID>", $7,"</NodeID>"}
{print " </Item>"}
END{print "</Slot_DB>"}' $TMP_FILE | tee $RESULT_FILE
rm -f $TMP_FILE