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

Hello all!

I've got a quick call out for help if anybody is willing. My company just started using a new credit card processing gateway. The response I receive upon sending the transaction comes back to me in a wannabe XML format but it isn't valid XML, so I can't use something like XML::Simple to parse it.

This is an example of what the response looks like:

<status>G</status><auth_code>TT1506</auth_code><security_result>M</sec +urity_result><order_number>0006-00310-38259</order_number>
Any ideas on what the easiest way to parse this would be? I would like to have it just stored in a hash (status=>G) or something simple like that.

Chad

Replies are listed 'Best First'.
Re: Text Parsing
by dws (Chancellor) on Apr 17, 2003 at 23:22 UTC
    The response I receive upon sending the transaction comes back to me in a wannabe XML format but it isn't valid XML, so ...

    What's the simplest thing you could do to make it valid XML?

    If you can do that, you can use XML::Simple.

    Sometimes, the easiest approach to a problem is to take one step sideways to get onto a better path.

Re: Text Parsing
by BrowserUk (Patriarch) on Apr 17, 2003 at 23:12 UTC

    #! perl -slw use strict; use Data::Dumper; my $trans = '<status>G</status><auth_code>TT1506</auth_code><security_ +result>M</security_result><order_number>0006-00310-38259</order_numbe +r> '; my %hash; $hash{$1} = $2 while $trans =~ m[<([^>]+)>(.*?)</\1>]g; print Dumper \%hash; __END__ C:\test>251350 $VAR1 = { 'status' => 'G', 'security_result' => 'M', 'order_number' => '0006-00310-38259', 'auth_code' => 'TT1506' };

    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.