I am having all sorts of troubles with this. I cannot seem to get this to work.
I send data to a website and it responds with something similar to this:
<?xml version = "1.0"?>
<response>
<custid>101010101</custid>
<status>success</status>
<responsecode>11</responsecode>
<kf></kf>
<cn>1111222233334444555</cn>
<neta>7.00</neta>
<prid>X111111111111111</prid>
<ano>22222222</ano>
<trxid>33333333</trxid>
<description>Transfer Completed</description>
</response>
I built a parser that goes through there and strips out this line:
<?xml version = "1.0"?>
then it gets all the data between the response tags, then I go parse out all the tags and I make a hash with the value being the data between the tags and the field being the name in the first tag, so the result should be something like this:
%_xml_response_data = (
'custid' => "101010101",
'status' => "success",
'responsecode' => "11",
'kf' => "",
'cn' => "1111222233334444555",
'neta' => "7.00",
'prid' => "X111111111111111",
'ano' => "22222222",
'trxid' => "33333333",
'description' => "Transfer Completed",
);
So that way I can use the data like a hash, for instance to see the status:
if($_xml_response_data{status} eq "success") {
# True so do whatever...
} else {
# false so do whatever else...
}
It was working, then I don't know something changed, and now even when the result is success, it seems to not recognize it. I figure, why re-invent the wheel, there MUST be something in cpan that works better, but there are sooooo many xml programs, I am completely lost...
The more I search the more complex they get.
Does anyone know of a easy to learn simple solution to get this working? It is not a lot of data, just a simple response.
Thanks,
Richard
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.