dinsdag 13 mei 2008

Rails : how to parse xml from url

require 'open-uri'
xmlfile = open('http://xmlfiles.com/file.xml').read

puts xmlfile['root']['item'].first['id'] # => gets you the first id of the xml file

Rails : Parsing xml to hash

I had an xml feed with no encoding attribute. It could parse parse it using Hash.from_xml(xmlfile). But as soon as the file contained special LATIN-1 characters, the code broke. I couldn't change the xml-file as it was a file from another server. But on the rails side I did this .insert(19,' encoding="ISO-8859-1"'). Now it works fine.

Linux : Searching string in files

find . | xargs grep '14'