From: Sebastian Reid Date: 2006-11-17T03:55:46+09:00 Subject: Re: parse xml file, put results in mysql db I don't recognise the ${} syntax in the string interpolation, is this just something I've not come across yet? Again, "#{variable}" is basically an expensive way of saying variable, try it without them. Additionally, what error are you getting? On 16 Nov 2006, at 17:35, Kathy Simmons wrote: > Here's the full code - I'm reading in nmap output in scanfile.xml and > want to put the data in a mysql db: > > #! /usr/bin/ruby > > require 'rexml/document' > require "mysql" > require "dbi" > include REXML > scanfile = File.new('scanfile.xml') > doc = Document.new(scanfile) > root = doc.root > > doc.elements.each("nmaprun") { |element| > puts element.attributes["args"] > args = element.attributes["args"] > puts element.attributes["startstr"] > timeofscan = element.attributes["startstr"] > puts element.attributes["version"] > version = element.attributes["version"] } > > doc.elements.each("nmaprun/scaninfo") { |element| > puts element.attributes["type"] > scantype = element.attributes["type"] > puts element.attributes["protocol"] > protocol = element.attributes["protocol"] > puts element.attributes["numservices"] > numservices = element.attributes["numservices"] > # puts element.attributes["services"] > services = element.attributes["services"] } > > doc.elements.each("nmaprun/scaninfo/host") { |element| > puts element.attributes["status state"] } > > # database insert > dbname="nmap" > m = Mysql.new("localhost", "root", "") > dbh=DBI.connect("dbi:Mysql:nmap:localhost", "root", "") > m.select_db(dbname) > sth=dbh.prepare("INSERT INTO rawdata > (file,tool,arguments,startime,version) VALUES (?,?,?,?,?)") > sth.execute("scanfile.xml", "nmap", "${args}", "#{timeofscan}", > "${version}"") > > > > -- > Posted via http://www.ruby-forum.com/. > >