Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3332430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:41:15+00:00 2026-05-17T23:41:15+00:00

In order to work with some client information I have been parsing a 3MB

  • 0

In order to work with some client information I have been parsing a 3MB XML file with hpricot… but hpricot takes quite some time to parse the file on a regular basis.

I am thinking about populating this data to a MySql db (once a week) so that I can work with the data directly on mysql with rails.

The file is basically is an XML Google Contacts File that contains client information: Name, email, notes… but also some contact contain multiple value fields such as addresses, telephones.

Currently when I am parsing the data I generate a Contact class

class Contact <
  Struct.new(:name, :email, :telephones, :addresses, :user_address,:notes)
end

telephones and addresses contain an array with the different values.

I guess that if I want to recreate this structure in the mysql database I would need to create three tables: contacts, telephones and addresses…

class Contact < ActiveRecord::Base
  has_many :addresses
  has_many :telephones
end

class Telephone < ActiveRecord::Base
  belongs_to :contact
end

class Address < ActiveRecord::Base
  belongs_to :contact
end

How would you to populate the Contact class data to the database tables?
Is there a way to insert the data directly from the XML file to the database tables?

Any advice and guidance will be greatly appreciated 🙂
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:41:15+00:00Added an answer on May 17, 2026 at 11:41 pm

    First why not give nokogiri a try and see if its faster ?

    Rails thought people best practices and they came to believe that there is a recipe on how one should program for any given problem. Unfortunately this is not the case, for the usual 90% of tasks there is no magic.

    So if you have a contact with some addresses and some telephones it’s just that.

    Here it’s how I would do:

    Parse the XML file, if it’s too big, stream the parsing.
    For each contact in it output a hash just like the params[:contact] would usually turn out in a controller after a form is submitted, and have the Contact model use accepts_nested_attributes_for.

    contact = {
      :name => xxx, 
      :user_address => xxx, 
      :notes => xxx
      :addresses_attributes => [
        {:some_attribute => xxx, :some_other_attribute => xxx}
        ...
      ],
      :telephones_attributes => [
        { :some_attribute => xxx, :some_other_attribute => xxx}
        ...
      ]
    }
    

    Now all that remains is:

    Contact.create(contact)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET site and I've been doing some work refactoring code to
I have a file in JSON format with record for individual users. Some of
For my customer I occasionally do work in their live database in order to
In order to debug an asp.net web app I have to have IE Script
In order to improve my open source project, I need testers. I have created
I have a challenge I need some input on. I am currently recruiting programmers
Essentially I need to retrieve some account information from the dbase table where they
I have an application that is a WinForm in C# that work with Oracle
I have encountered many half-solutions to the task of returning XML in ASP.NET. I
We have built a Windows Service that is running on client's machines, which occasionally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.