Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to XML SOAP Response by mitchismoney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found