用java写不胜其烦,得连接数据库,得用jdom转换XML文件,用Shell写只有下面几行:
# /usr/local/bin/mysql2xml
TMP_FILE=tmp.txt
RESULT_FILE=slot.xml
mysql -uroot -p123456 -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{printf "<Slot_DB>\n"}
{printf " <Item>\n"}
{printf " <DB_Owner>%s</DB_Owner>\n", $1}
{printf " <DB_Tab>%s</DB_Tab>\n", $2}
{printf " <DB_Attr>%s</DB_Attr>\n", $3}
{printf " <SlotName>%s</SlotName>\n", $4}
{printf " <SlotID>%s</SlotID>\n", $5}
{printf " <NodeName>%s</NodeName>\n", $6}
{printf " <NodeID>%s</NodeID>\n", $7}
{printf " </Item>\n"}
END{print "</Slot_DB>"}' $TMP_FILE | tee $RESULT_FILE
rm -f $TMP_FILE