Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help with XML and Perl

XML and PERL

         

western55

1:01 am on Aug 15, 2003 (gmt 0)

10+ Year Member




Any help would be appreciated. I am trying to replace a variable with data within the $req = statement but it is not working.

Any help would be appreciated..

Example:

use HTTP::Request::Common qw (POST);
use LWP::UserAgent;
use XML::Parser;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;
use CGI;
$cc = '4168';

$ua = LWP::UserAgent->new();
my $req = POST 'https://xml.payments.com',
[ name => '<EngineDocList>
<DocVersion>1.0</DocVersion>
<EngineDoc>
<ContentType>OrderFormDoc</ContentType>
<User>
<Name>$cc</Name>
</User>
</EngineDocList>' ];

my $response = $ua->request($req);
if($response->is_error) {
printf " %s\n", $response->status_line;
}
else
{
my $count;
my $bytes;
my $content = $response->content();
# $p = new XML::Parser(Style => 'Debug');

my $p = new XML::Parser(ErrorContext => 2,
Handlers => {Start => \&start_handler,
End => \&end_handler

Damian

10:03 am on Aug 15, 2003 (gmt 0)

10+ Year Member



Welcome to Webmasterworld western55.

I don't see any replacement attempts in your code so I'm not sure people will understand your exact problem with that code snippet.

Looks like $req only contains a value for the URL.. so if you want to replace something in the URL maybe you could do the replacement before making it part of $req?

western55

4:46 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



Thanks for the welcome Damian.

I am actually trying to replace the $cc between the <name> tages with an actual order number assigned at the top. However, when it posts the file to the URL, it sends $cc instead of what $cc contains..

It's driving me CRAZY...

-Mark

Damian

5:23 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



Ok, I understand the problem. Don't know why it won't work, but maybe you can do the replacement outside of $req?

something like

my $xml = qq~
<EngineDocList>
<DocVersion>1.0</DocVersion>
<EngineDoc>
<ContentType>OrderFormDoc</ContentType>
<User>
<Name>$cc</Name>
</User>
</EngineDocList>'
~;

That really should work ..:)
and then

my $req = POST 'https://xml.payments.com',
[ name => '$xml' ];

I haven't tried it but maybe it helps..
<added> On second thought it probably won't work..
if it prints $xml try it without the quotes.. it's a longshot but who knows.. </added>

western55

7:10 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



Thanks Damian,

It did work. (without the quotes)

Thanks, you've reduced my stress level 300%..

-Mark