Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML query

Status
Not open for further replies.

tar565

Programmer
Jan 24, 2005
39
IE
I have never had to work with XML before and I am looking for a way to read an XML file post it to a url and read the response. Any help would be great as this is a complete new one for me
 
Maybe these two modules will help you

XML::parser #for handle XML file
LWP::UserAgent #for Get/Post files and handle request/response

there are many more modules though for handling XML files


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Actually reading is not a problem I just want to upload it and get a response.
 
pengo's right -you can use LWP::UserAgent for that. Have a look at the section on POST in lwpcook
 
ok i have found the following script. How can I upload an xml file called test.xml with it

use LWP::UserAgent;
use HTTP::Request;

my $ua = LWP::UserAgent->new(env_proxy => 1, keep_alive => 1, timeout => 30, );

my @greeting = <>; #-- Read file containing XML struct to send
my $data_to_send; #-- And build a string of it
foreach my $newItem (@greeting) {
$data_to_send = "$data_to_send$newItem";
}

print "Sending :\n$data_to_send\n";

#-- Create the Request Object and send the data
my $response =
$ua->request(HTTP::Request->new('GET', 'HTTP::Headers->new(Content_Type => "text/xml"), $data_to_send));

#-- Print the response
print $response->as_string;
 
Try like this
Code:
use strict;
use warnings;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();

[red]undef $/;
open FILE, "yourXMLfile.xml";
my $data_to_send = <FILE>;
close FILE;
[/red]
print "Sending :\n$data_to_send\n";

my $response = $ua->request(HTTP::Request->new('GET', '[URL unfurl="true"]http://your/web/server/for/uploading/',[/URL]
HTTP::Headers->new(Content_Type => "text/xml"), $data_to_send));

print $response->as_string;
I haven't try it though ......


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top