I have been trying to find specific enough example on how to proceed. I am creating xml file with Builder for export/import use. I am exporting this file from app and when importing I want to create new records to database based on this xml file. With relations between models intact.
I have category with several questions, each question has several answers which might trigger one or more further questions.
I made simplified version of my xml file: https://gist.github.com/1225431
As I am doing it by myself, I am also open to suggestions if I should prepare that xml file differently.
questions = doc.css('questions')
This is where I am now, so right at the beginning. All the examples I have found have been for totally different kind of problems (or so I feel).
Am I even using right tool for this job? Any help appreciated.
Nokogiri is a great XML/HTML parsing library for Ruby, so you’re definitely using the right tool for the job. Since you’re parsing an XML document, you ought to use XPath instead of CSS selectors. Fortunately, Nokogiri has you covered.
The Nokogiri documentation has a few basic, helpful usage tutorials. This one answers your question.
Here is a code example specific to your question. Hopefully this is enough to get you started: