Posts

Showing posts with the label XML

[Level 3] XML in MySQL.

#!/usr/bin/bash createTable() { mysql -ujoseph <<EOF CREATE TABLE persons ( id int auto_increment primary key, data text ); EOF } #createTable createUsers(){ mysql -ujoseph <<EOF INSERT INTO persons(data) values (' <person> <name>stanley</name> <sex>m</sex> <addr>taipei</addr> <tels> <tel>12340001</tel> <tel>12340002</tel> <tel>12340003</tel> </tels> </person> '), (' <person> <name>joseph</name> <sex>m</sex> <addr>taipei</addr> <tels> <tel>12350001</tel> <tel>12350002</tel> <tel>12350003</tel> </tels> </person> ') ; EOF } #createUsers queryUserTels() { mysql -ujoseph <<EOF select ExtractValue(data,'//person/tels/tel[1]'), ExtractValue(data,'/person/tels/tel[2]'), ExtractValue(data,'person/tel...

[Level 2] MySQL XML Functions.

One day, a friends of mine asked me if MySQL support XML? Actually, MySQL havs two XML functions, called "ExtractValue" and "UpdateValue". You can use these two function as the following samples: mysql> CREATE TABLE persons ( id int auto_increment primary key, data text ); mysql> INSERT INTO persons(data) values (' <person>   <name>stanley</name>   <sex>m</sex>   <addr>taipei</addr>   <tels>     <tel>12340001</tel>     <tel>12340002</tel>     <tel>12340003</tel>   </tels> </person> '), (' <person>   <name>joseph</name>   <sex>m</sex>   <addr>taipei</addr>   <tels>     <tel>12350001</tel>     <tel>12350002</tel>     <tel>12350003</tel> ...