Importing XML into a database with Scriptella ETL
1 2 <!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"> 3 <etl> 4 <connection id="in" driver="xpath" url="http://snippets.dzone.com/rss"/> 5 <connection id="db" driver="hsqldb" url="jdbc:hsqldb:db/rss" user="sa" classpath="hsqldb.jar"/> 6 classpath="hsqldb.jar"/> 7 <query connection-id="in"> 8 /rss/channel/item 9 <script connection-id="db"> 10 INSERT INTO Rss (ID, Title, Description, Link) 11 VALUES (?rownum, ?title, ?description, ?link); 12 </script> 13 </query> 14 </etl>
Here is the full version of the example described above. It creates an RSS table, downloads rss file, inserts rss records into a database, converts rss.xml to a plain text file and saves it to rss.txt.
1 2 <!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"> 3 <etl> 4 <connection id="in" driver="xpath" url="http://snippets.dzone.com/rss"/> 5 <connection id="out" driver="text" url="rss.txt"/> 6 <connection id="db" driver="hsqldb" url="jdbc:hsqldb:db/rss" user="sa" classpath="hsqldb.jar"/> 7 <script connection-id="db"> 8 CREATE TABLE Rss ( 9 ID Integer, 10 Title VARCHAR(255), 11 Description VARCHAR(255), 12 Link VARCHAR(255) 13 14 ) 15 </script> 16 <query connection-id="in"> 17 /rss/channel/item 18 <script connection-id="out"> 19 Title: $title 20 Description: [ 21 ${description.substring(0, 20)}... 22 ] 23 Link: $link 24 ---------------------------------- 25 </script> 26 <script connection-id="db"> 27 INSERT INTO Rss (ID, Title, Description, Link) 28 VALUES (?rownum, ?title, ?description, ?link); 29 </script> 30 </query> 31 </etl>