|
|
Question : syntax for Win32::Ole xml POST using MSXML 4 core services
|
|
I believe it is possible to use Win32::Ole and MSXML 4 core services to post xml data to a database but I don't know the proper syntax. Can someone provide the proper code? I am trying to convert some javascript from an asp page that does this to PERL. I want to try the Win32::Ole/MSXML route because I haven't yet gotten non-MSXML-dependant PERL code to work, I have MSXML core services installed on my servers, I know the asp/MSXML-dependant code works, but I don't want to mix asp and perl unless I absolutely have to.
These links indicate it is possible to access MSXML 4 via PERL. http://www.perl.com/pub/a/2001/04/17/msxml.html http://www.mail-archive.com/perl-win32-users@listserv.activestate.com/msg27266.html http://perl-xml.sourceforge.net/faq/#msxml
Here is the ASP/javascript I'd like to convert to perl (I've already got the xml query string available): function submitWpXml(xmlString) { // create an instancee of the MSXML 4 ServerHTTPRequest object to send XML to WPPro var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.4.0"); sServerName = Request.ServerVariables("SERVER_NAME");
if (sServerName == "") sServerName = "localhost"; // Initializes an MSXML2.ServerXMLHTTP request and specifies the method, URL, and authentication information for the request. xmlhttp.open( "POST", "http://"+sServerName+"/dbtw-wpd/exec/dbtwpub.dll", false, "", "" ); //UPDATE FOR RELEASE //set header xmlhttp.setRequestHeader( "Content-Type", "text/xml" ); xmlhttp.send (xmlString); // send the xml to WP Pro and wait for a response
// get the response from WP as a string of text, return xmlhttp.responseText; //return xmlhttp.responseXML would get the repsponse as an xml object }
Note: I am asking this question in parallel w/another question I asked at: http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_21021354.html. In that question, kandura has helped me w/formatting the xml query string, but we have not yet accomplished a successful xml post of the query (which adds a record to a db).
|
Answer : syntax for Win32::Ole xml POST using MSXML 4 core services
|
|
Basically what I tried to suggest is to try to limit the number of global variables to the bare minimum, and use local variables as much as you can. That way the code in the subroutines is as self-contained as possible. Strictly speaking, functions should only operate on their input, and return the interesting bits to the caller. In this script it doesn't matter a whole lot, but it's good advice for bigger programs. Global variables are a prime source of difficult to find bugs, especially when different subs do different things to them.
The subs would be changed to something like this:
sub processWpXml { my $xml = shift; my ($strRecInfo, $strAC, ...); ... return ($strRecInfo, $strAC, ...) ; }
sub printYourOutputHere { my ($strRecInfo, $strAC, ...) = @_; ... }
and at the top, you'd do
my @output = processWpXml( $strReturnedXml ); printYourOutputHere( @output );
I must admit that it doesn't look much clearer that way... If it works, then keep it like it is. Maybe it's just general advice that you might be able to use in a future script.
|
|
|
|
|