Wednesday, July 7, 2010

learning XSLT and xml to csv to Oracle or MySQL

I have been learning some XSLT
Here is a good place to start learning how to use it to convert xml to html.
This is the page on W3 schools teaching about the for-each loop that lets you loop through the xml code then you can select the xml elements you want to grab.

You can also convert xml to csv and then to a database if you want. Here is a good tutorial on how to do this:

Also if you want to take a csv file and put it into a MySQL database this is what you do:
DROP TABLE IF EXISTS movie;
CREATE TABLE movie ( role VARCHAR(30) , actor VARCHAR(30) , movie VARCHAR(60)) engine=memory;

TRUNCATE movie;
LOAD DATA LOCAL INFILE 'path_to_csv/movie.csv'
INTO TABLE movie
FIELDS TERMINATED BY '\t'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;

The csv is taken into the table with the load data local infile command.
Drop table will drop the table so you can create it again next time you use this command so it is a re-runnable script.
Truncate just removes all data in the table. The Oracle script on blog.mclaughlinsoftware.com uses an external table which makes it so when you read from the table movie you are really reading from the csv file so when ever you change the csv the data in the database is automatically changed when you read from it next. Like:
SELECT * FROM movie;





No comments: