in reply to grabbing XML in a script

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.

Replies are listed 'Best First'.
Re: Re: grabbing XML in a script
by mirod (Canon) on Oct 16, 2003 at 08:46 UTC

    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!)...