HTTP Query Request & Parsing returned XML output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HTTP Query Request & Parsing returned XML output
# 8  
Old 05-12-2005
learning new stuff

Speaking of learning new stuff, I have an issue that needs to be resolved in a perl program.

#! /usr/bin/perl

use LWP::UserAgent;
$ua = LWP::UserAgent->new;

$ua->agent("0/0.1 " . $ua->agent);

$Supplier = '201330-01';
$Plant = 'XXX';
$Contact = 'NMD';

$qry = 'http://xxx.xxxxxx.com/servlet/eDCISSupplierServlet?Supplier=' . $Supplier . '&Plant=' . $Plant . '&Group=' . $Contact;

print "The query is \n";
print $qry . "\n";
$req = HTTP::Request->new(GET => '$qry');
$req->header('Accept' => 'text/xml');

$res = $ua->request($req);

if ($res->is_success) {
print $res->content;
} else {
print "Error " . $res->status_line . "\n";
}

The above Code returns the following
The query is
http://xxx.xxxxxx.com/servlet/eDCISS...=XXX&Group=NMD
Error 400 URL must be absolute

However if I execute the URL from ie I get an XML stream as a result. The xxx.xxxxxx.com is a lotus notes Dominos server. Any ideas as to how to over come this issue? Thanks.
# 9  
Old 05-12-2005
Quote:
Originally Posted by jerardfjay
$req = HTTP::Request->new(GET => '$qry');
This should read

Quote:
$req = HTTP::Request->new(GET => "$qry");
or just simply

Quote:
$req = HTTP::Request->new(GET => $qry);
Does this fix it?
# 10  
Old 05-12-2005
singe versus double quote

Quote:
Originally Posted by cbkihong
This should read



or just simply



Does this fix it?
Thank you so much. I didnt have a clue as to what was causing this issue. If I may ask, why the difference between the single versus double quote.
# 11  
Old 05-13-2005
You passed exactly the string '$qry' as the URL, which is wrong. Variable names will not be expanded if they appear in single quotes.

From the perldata manpage:
Quote:
String literals are usually delimited by either single or double quotes. They work much like quotes in the standard Unix shells: double-quoted string literals are subject to backslash and variable substitution; single-quoted strings are not (except for \' and \\ ).
# 12  
Old 05-13-2005
I received the following private message from you. As I mentioned in my reply message, let us make more contribution to the knowledge base by keeping technical discussions in the forums, so I give my response here.

Quote:
Thanks for helping me with my PERL posts. Can you help me parse the following output stream stored in the var res->content.

<SUPPLIERS>
<SUPPLIER>
<NAME>Margie Siedow</NAME>
<EMAIL>mssiedow@mmm.com</EMAIL>
</SUPPLIER>
</SUPPLIERS>

I can have zero or more <Name> <Email> values and I just need to parse out <Email> values. How can I do this in PERL. Please advise. Thanks.
I think XPath will give the shortest code (not necessarily the fastest).

Code:
use XML::XPath;
$xml = new XML::XPath(xml => $res->content);
@aryEmailAddr = ();
for ($xml->findnodes('//EMAIL')) {
 push(@aryEmailAddr, $_->string_value);
}

This should give you an array of email addresses (if found). I think by now you should be able to do some research and work on your own.
# 13  
Old 05-17-2005
Quote:
Originally Posted by cbkihong
I received the following private message from you. As I mentioned in my reply message, let us make more contribution to the knowledge base by keeping technical discussions in the forums, so I give my response here.
Thank you cbkihong. Since I do not have access to install XML::XPath module on our system over here, I have decided to write a simple program which essentially does what you have provided in 4 or 5 lines. Here is the code for the same.

#! /usr/bin/perl
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("0/0.1 " . $ua->agent);
$Supplier = '201330-01';
$Plant = 'XXX';
$Contact = 'ABC';

$qry = 'http://nshamd02.ham.am.honda.com/servlet/eDCISSupplierServlet?Supplier=' . $Supplier . '&Plant=' . $Plant . '&Group=' . $Contact;

print "The query is \n";
print $qry . "\n";
$req = HTTP::Request->new(GET => "$qry");
$req->header('Accept' => 'text/xml');

$res = $ua->request($req);

if ($res->is_success) {
open(MAIL, ">.mail.tmp");
print MAIL $res->content;
close(MAIL);
open (FP, ".mail.tmp");
while (<FP>) {
if (/EMAIL/) {
$mail = $_;
$mail =~ s/EMAIL//g;
$mail =~ s/\<//g;
$mail =~ s/\>//g;
$mail =~ s/\///g;
$mail =~ s/^ //g;
$mail =~ s/ *//g;
print $mail;
}
}
unlink ".mail.tmp";
} else {
print "Error " . $res->status_line . "\n";
}

Jerardfjay
# 14  
Old 05-17-2005
I don't have most of these modules installed systemwide for my projects. I just extract them, put them at appropriate places in my source project dirs and point @INC to there, and they will work. At least, non-compiled modules can be installed likewise, to avoid having to always rely on the system offerings.

If your servlet application is instructed to write in strictly this form (the element and its text node on a separate line) then it will be okay, but note that the XML specification states that whitespace between tags are insignificant and so you need to watch out if the XML generation component has changed at the servlet side (for instance, I think the Sun Java XML parsers do not write spaces or newlines in between tags). And you need to watch out for characters encoded (such as &gt; and &lt;) to comply with the XML standard by the generator. That is why using "standard" means such as SAX/DOM/XPath will be more convenient as your XML structure becomes more complex.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SQL query output convert to HTML & send as email body

Hi , I have a sql query in the unix script ,whose output is shown below.I want to convert this output to HTML table format & send email from unix with this table as email body. p_id src_system amount 1 A 100 2 B 200 3 C ... (3 Replies)
Discussion started by: jagadeeshn04
3 Replies

2. Shell Programming and Scripting

Parsing the http post request

Hi, I am trying to write a shell script to parse the post request data that it received to a xml file. Below is the post request data that script is receiving. -----------------------------7dd2339190c8e Content-Disposition: form-data; name="param1" 1... (2 Replies)
Discussion started by: jdp
2 Replies

3. Shell Programming and Scripting

Help in parsing XML output file in perl.

Hi I have an XML output like : <?xml version="1.0" encoding="ISO-8859-1" ?> - <envelope> - <body> - <outputGetUsageSummary> - <usgSumm rerateDone="5"> - <usageAccum accumId="269" accumCaptn="VD_DP_AR" inclUnits="9999999.00" inclUnitsUsed="0.00" shared="false" pooled="false"... (7 Replies)
Discussion started by: rkrish
7 Replies

4. Shell Programming and Scripting

http request

I am running a website but I still have problems with the "service temporarily unavailable error". I want to make a simple check if the website is up and running. Does anybody has an idea how to do it? (the site is password protected, so you have to add a user and pwd before logging in). ... (2 Replies)
Discussion started by: jurgen
2 Replies

5. Shell Programming and Scripting

Capture query returned values in file.

Hi All, I am connecting to Oracle DB from UNIX script. Want to capture all dates between start date and end date and store them in file. Once this is done, want to read dates one by one. How to achive this in UNIX and Oracle? Please let me know if you have any idea on the same. Thanks and... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

6. Shell Programming and Scripting

Awk & sed query for output

Hello, I have a file. its content are like below. mdn:87439842 imsi:23082038203 Ctime:12082010 01:20:10 mdn:9324783783 imsi:402349823322 Ctime: 12072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime: 23072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime:18072010 01:20:10 mdn:87439842... (3 Replies)
Discussion started by: Sanket11
3 Replies

7. Shell Programming and Scripting

How to send XML data using HTTP Post Request

How to hit HTTP Post Request along with sending XML data to a Remote server through command line utility like wget (or anything else). (0 Replies)
Discussion started by: sandeep reddy
0 Replies

8. UNIX for Dummies Questions & Answers

HTTP request

Can anybody tell about http request processing in shell script..? (3 Replies)
Discussion started by: noufal
3 Replies

9. Shell Programming and Scripting

Http request in Linux

Hi, i need a guide how to write a script which i can do a http request. Let say the request look like below; http://www.test.com?txid=1&type=service&server=linux I have a list of "txid" (in *.txt) and need to run all "txid" acordingly. So that mean, every transaction i have to refer "txid"... (7 Replies)
Discussion started by: malaysoul
7 Replies

10. SCO

XML Import & HTTP Post

this may be very basic to some but all new to me I have an application running on SCO Unix server which issues an HTTP Post request to a server with the results being returned in I.E browser window in XML format I need to import these results into my customers application and dont know how to... (1 Reply)
Discussion started by: ccarcher
1 Replies
Login or Register to Ask a Question