tags:

views:

66

answers:

2

Hi,

I am making a simple Python CGI script that collects data(in xml format) from a flex application and I want to insert it into the mysql database .

In perl The script is looks like the following...

my @samplexml=$cgi->param("Items");

my $data=$xml->XMLin("@samplexml");

foreach my $e(@{$data->{Group}})
{
   my $sample="Insert into details(title,Parent,Istreeitem) Values('$e->{title}','$e->{Parent}','$e->{IsTreeItem}')";
   my $sam=$dbo->prepare($sample);
   $sam->execute();
}

But I want to know how to write these codes in pytrhon script.... Any one can help me?

Thanks in advance. Nimmy.

A: 

It should be fairly easy to convert this to a Python script. Setting the stage:

  1. Python has the cgi module.
  2. Get the Python-MySQL library (or an equivalent for whatever db you're using).
  3. Use Python's xml.etree to parse the incoming XML.

You'd write a Python script that'd read the XML from the CGI variables, parse the xml using xml.etree, make a connection to the database, and execute your exact insert statement. The resulting script should look very similar to the above.

rlotun
Can you give a sample code?
Nimmy
A: 

If you're not bound to XML, you can consider pyAMF and flex's remoteobjects or other remoting facilities.

Gary