http://qs1969.pair.com?node_id=738070

palette has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have a very simple script to post XML using curl to an URL
$xml ='<?xml version="1.0" encoding="UTF-8"?> <TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <TEST1> <ID>1223</ID> <DESCRIPTION>XXXXX</DESCRIPTION> </TEST1> </TEST> '; $curl ='/usr/local/bin/curl --silent -m 120 -d "'.$xml.'" '. 'http://l +ocalhost/check.cgi'; $responsexml = `$curl`; print $responsexml;
On executing the script I am getting this error.
org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Pls let me know what is the reason for this error, and what needs to be verified to make it work.

Replies are listed 'Best First'.
Re: Curl with perl
by fullermd (Priest) on Jan 22, 2009 at 07:32 UTC

    Well, for one thing, note that you're including on the command-line a double-quoted string (the $xml), containing double-quotes. That doesn't tend to work well. Perhaps you should try using open to pass in the args as an array and grab the output?

    @curl = ('/usr/local/bin/curl', '--silent', '-m', '120', '-d', $xml, 'http://localhost/check.cgi'); open CURL, "-|", @curl; @responsexml = <CURL>; print @responsexml;

    (untested)

    As for the error you gave, there's nothing in the code you posted that would get near SAX (whether there's any surrounding code that may, you haven't said enough to guess). And I don't think curl uses it either. So presumably, that's coming from the server and has nothing (directly) to do with this code anyway.

Re: Curl with perl
by dHarry (Abbot) on Jan 22, 2009 at 08:49 UTC

    org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.

    This is a known problem, past the error message into Google and find the solution. Hint: "well-formedness".

Re: Curl with perl
by clscott (Friar) on Jan 23, 2009 at 00:47 UTC
    Are you aware of LWP? It could make your life easier
    $xml ='<?xml version="1.0" encoding="UTF-8"?> <TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <TEST1> <ID>1223</ID> <DESCRIPTION>XXXXX</DESCRIPTION> </TEST1> </TEST> '; use LWP::UserAgent; my $curl = LWP::UserAgent->new( timeout => 120 ); my $response = $curl->post($url, Content => $xml); if ($response->is_success) { print $response->decoded_content; # or whatever } else { die $response->status_line; }
    --
    Clayton