http://qs321.pair.com?node_id=701466

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

New Monk seeking wisdom about parsing a soap response. I have a soap response from a VB Script that saves as XML. I would like to grab this file with PERL, parse it and store it in a database, either in full XML string or parsed by element. My problem is that the output I'm getting from XML::Parse is not very friendly. I think its an encoding issue but I'm not sure how to get around it.
<?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <ns1:VHIResponse xmlns:ns1="http://tempuri.org/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" +> <return xsi:type="xsd:string"> &lt;Vehicles&gt; &lt;Vehicle vin=&quot;1FMFU17L94LB04622&quot;&gt; &lt;Status desc=&quot;Vehicle status OK&quot; id=&quot;VI1000&quot;/&g +t; &lt;VehicleAttributes&gt; &lt;VehicleAttribute type=&quot;Year&quot; typeid=&quot;14&quot; value +=&quot;2004&quot; valueid=&quot;3043&quot;/&gt; &lt;VehicleAttribute type=&quot;Make&quot; typeid=&quot;1&quot; value= +&quot;Ford&quot; valueid=&quot;184&quot;/&gt; &lt;VehicleAttribute type=&quot;Model&quot; typeid=&quot;2&quot; value +=&quot;Expedition&quot; valueid=&quot;30&quot;/&gt; &lt;VehicleAttribute type=&quot;Series&quot; typeid=&quot;3&quot; valu +e=&quot;Eddie Bauer&quot; valueid=&quot;117&quot;/&gt; &lt;/VehicleAttributes&gt; &lt;/Vehicle&gt; &lt;/Vehicles&gt; </return> </ns1:VHIResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Thanks for the responses, I spaced out on posting the PERL code. Ultimately I would like to see something like:
<FCSDServicesResponse country="USA" language="ENG" marketid="1"> <Status desc="Web service status OK" id="VI2000"/> <Vehicles> <Vehicle vin="1FMFU17L94LB04622"> <Status desc="Vehicle status OK" id="VI1000"/> <VehicleAttributes> <VehicleAttribute type="Year" typeid="14" value="2004" valueid="3043"/ +> <VehicleAttribute type="Make" typeid="1" value="Ford" valueid="184"/> <VehicleAttribute type="Model" typeid="2" value="Expedition" valueid=" +30"/> <VehicleAttribute type="Series" typeid="3" value="Eddie Bauer" valueid +="117"/> </VehicleAttributes> </Vehicle> </Vehicles> </FCSDServicesResponse>
All I really need extracted is the VIN/Make/Model/Year and Series from the resulting response. I am relatively new to this so I'm starting out slow with the basics:
# use module use XML::Simple; use Data::Dumper; # create object $xml = new XML::Simple; # read XML file $data = $xml->XMLin("Elvis1.xml"); # print output print Dumper($data);
What I get from this is:
$VAR1 = { 'country' => 'USA', 'language' => 'ENG', 'Status' => { 'desc' => 'Web service status OK', 'id' => 'VI2000' }, 'Vehicles' => { 'Vehicle' => { 'VehicleAttributes' => { 'VehicleAt +tribute' => [ + { + 'typeid' => '14', + 'value' => '2004', + 'valueid' => '3043', + 'type' => 'Year' + }, + { + 'typeid' => '1', + 'value' => 'Ford', + 'valueid' => '184', + 'type' => 'Make' + }, + { + 'typeid' => '2', + 'value' => 'Expedition', + 'valueid' => '30', + 'type' => 'Model' + }, + { + 'typeid' => '3', + 'value' => 'Eddie Bauer', + 'valueid' => '117', + 'type' => 'Series' + } + ] }, 'Status' => { 'desc' => 'Vehicle st +atus OK', 'id' => 'VI1000' }, 'vin' => '1FMFU17L94LB04622' } }, 'marketid' => '1' };
Many Thanks in advance. Darren