Need to generate xml to be stored in a database


#1

Forgive my ignorance, but I have searched for a while and cannot find
anything that would help me move in the right direction.
I need to generate xml that will then be recored in the database so
that I can pull out at a later date.
Every bit of info I could find shows how to create the xml and display
it through a .rxml view.

I also have to be able to assemble the data points for the xml from
several different tables (I basically need to pull all of the has_one
and has_many relationships for a particular table and construct the
xml with them).

A push in the right direction would be awesome.

Thanks.


#2

On Nov 3, 9:51 pm, “casey.ellett” removed_email_address@domain.invalid wrote:

Forgive my ignorance, but I have searched for a while and cannot find
anything that would help me move in the right direction.
I need to generate xml that will then be recored in the database so
that I can pull out at a later date.
Every bit of info I could find shows how to create the xml and display
it through a .rxml view.
Check out the builder library - it’s what rxml templates use.

Fred


#3

On 4 Nov 2008, at 13:54, Casey Ellett wrote:

I have successfully been able to create the xml I needed as a view,
but how do I go from that to storing it as a record in the database?

Well, having generated the xml, what’s stopping you assigning it to
some attribute of some ActiveRecord object ?

Fred


#4

I have successfully been able to create the xml I needed as a view, but
how
do I go from that to storing it as a record in the database?

On Mon, Nov 3, 2008 at 5:44 PM, Frederick C.
<removed_email_address@domain.invalid


#5

My complete lack of knowledge of how I would do that. I am very new to
this.
Can I handle that in the method I’ve put in the controller to collect
the
data and render the xml?

Currently I am just pulling in a specific category object in the
controller
and specifying a view:

def cat_xml
@category = Category.find(params[:id])

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :action => "cat.xml.builder", :layout => 

false }
end

end

And I have the xml Builder template in:

cat_xml.xml.builder

Where would I assign this view to an ActiveRecord object?

Or am I going down the wrong path here? I don’t actually need to view
the
xml at any point - I’m actually going to pull it out of the database at
a
later point and send it up to a web service. Or I guess I could send it
as
it’s generated, I just want to save it to pull it later if need be.

Thanks for taking an interest in helping me out, by the way.

On Tue, Nov 4, 2008 at 9:19 AM, Frederick C.
<removed_email_address@domain.invalid


#6

On Tue, Nov 4, 2008 at 11:09 AM, Frederick C. <
removed_email_address@domain.invalid> wrote:

Or am I going down the wrong path here? I don’t actually need to
view the xml at any point - I’m actually going to pull it out of the
database at a later point and send it up to a web service. Or I
guess I could send it as it’s generated, I just want to save it to
pull it later if need be.

We do this very same thing. It may or may not be the best solution, but
we
store the xml in a temp file on the server, and then have the path
listed in
our MySQL database as text. We just read the whole thing and pass to the
web
service when we’re ready to move on.

Our process goes like this:

  1. Customer creates a cart and checks out.
  2. Call web services to generate the completed order xml.
  3. Save order xml into temp text file and put the path into the db.
  4. Display confirmation page with totals/taxes (generated from web
    service).
  5. If confirmed, read order xml and call save method in web service.

It’s simple and doesn’t require a whole bunch of coding. It also gives
you
a nice history to look at if there are any problems with the xml.

We remove the xml temp file once the order has been completed so it
doesn’t
eat all of our server space.

Hope this helps!


#7

I’ll give this a go tonight. Thanks.


#8

I got this sorted out.

I ended up creating the new ActiveRecord object and passing the xml from
builder into that.

Thank you for your help.


#9

On 4 Nov 2008, at 15:04, Casey Ellett wrote:

cat_xml.xml.builder

Where would I assign this view to an ActiveRecord object?

Or am I going down the wrong path here? I don’t actually need to
view the xml at any point - I’m actually going to pull it out of the
database at a later point and send it up to a web service. Or I
guess I could send it as it’s generated, I just want to save it to
pull it later if need be.

If you don’t have a view, you don’t need a template. you can do
something like

xml = Builder::XmlMarkup.new(:indent => 2)
xml.instruct!
#buildery stuff here

SomeObject.create :xml_text => xml.target!

Fred