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

Thanks ahead of time for all your help.

What i need to do is setup a program that will be called by an outside program that will also pass to it XML. how can i get my program to store the incoming xml into a variable?

for example the calling program will do something link this:
use Win32::OLE; my $SendObject = Win32::OLE->new('microsoft.XMLhttp'); $SendObject->open("POST", 'http://www.xyz.com/my_prog.cgi', "false"); $SendObject->setRequestHeader("Content-type", "text/xml"); $SendObject->send($XML_INFO);
Now i need my_prog.cgi to grab the xml info coming in and i am unsure how to accomplish this.

thanks

Replies are listed 'Best First'.
Re: grabbing XML in a script
by idsfa (Vicar) on Oct 15, 2003 at 21:14 UTC

    Look at XML::Simple, which slurps incoming XML into a hash.

    use XML::Simple; my $data = ""; { local $/; $data = <STDIN>; } my $ref = XMLin($data); print $ref->{xml-key};

    Remember, when you stare long into the abyss, you could have been home eating ice cream.

      You can't really advise using XML::Simple without knowing what kind of XML is being exchanged: if it contains mixed content then XML::Simple will not be very useful. Don't get me wrong, I love XML::Simple when appropriate, but it just should not be recommended blindly.

      You can try this at home to see wht I mean BTW:

      perl -MXML::Simple -MYAML -e'print Dump XMLin "<doc>\ text with <b>mixed content</b>:\ you see that <tt>XML::Simple</tt>\ kinda <i>messes it-up</i>.</doc>"'

      Other recommended solutions include XML::LibXML (if you can install it), XML::TreeBuilder, one of the XML::SAX modules, or XML::Twig (of course!)...