Hello Monks,

I have been trying to make this code work for days but failed.

This is the CGI code reciving the XML from a client.

I would like to insert the messageId and text to MySql DB.

#!/usr/bin/perl -w use strict; use Time::Piece; use warnings FATAL => 'all'; use CGI qw(); use POSIX qw/strftime/; use LWP::UserAgent; use HTTP::Request; use XML::Simple; use SOAP::WSDL; use SOAP::WSDL::Deserializer::Hash; use SOAP::Lite; use Time::Piece; use XML::LibXML; use XML::Twig; use Data::Dumper; use DBI; my $cgi = CGI->new; print $cgi->header(-type => "text/xml", -charset => "utf-8"); my $xml = $cgi->param("POSTDATA"); my $dbh = DBI->connect("DBI:mysql:smscenter", "smscenter", "smsc1234", +{ RaiseError => 1, AutoCommit => 1 }); $dbh->trace(2); my $sql1 = 'INSERT INTO test(test,test1) VALUES(?,?)'; my $sth1 = $dbh->prepare($sql1); my $twig = new XML::Twig( twig_handlers => { ServiceException => \&ServiceException, } ); $twig->parse($xml); sub ServiceException { my ( $twig, $ServiceException ) = @_; my @f = ( $ServiceException->field('messageId'), $ServiceException->field('text'), ); print $f[0], "\n"; print $f[1], "\n"; $sth1->execute( @f ) or die $DBI::errstr; }

The XML being sent is this

<?xml version=\"1.0\" encoding=\"utf-8\"?> <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/enve +lope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> <soapenv:Body> <soapenv:Fault> <faultcode>SVC0008</faultcode> <faultstring>Duplicate SMS notification, criteria is default criteria, + centralCode is 20245</faultstring> <detail> <ns1:ServiceException xmlns:ns1=\"http://www.csapi.org/schema/parlayx/ +common/v2_1\"> <messageId>SVC0008</messageId> <text>Duplicate SMS notification, criteria is default criteria, centra +lCode is 20245</text> <variables>default criteria</variables> <variables>20245</variables> </ns1:ServiceException> </detail> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>

Where am I going wrong.

Really need your assistance.

Thank you.


In reply to CGI Server Insert XML Data to Mysql by bendon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.