Loading ...
Sorry, an error occurred while loading the content.

Newbie question: parsing XML response

Expand Messages
  • Frank Bulk
    I searched google and scoured the newsgroup, but couldn t find a way to parse a nested response. Here s my code: ======== #!perl -w use strict; use SOAP::Lite
    Message 1 of 1 , Jul 21, 2006
    • 0 Attachment
      I searched google and scoured the newsgroup, but couldn't find a way to
      parse a nested response.

      Here's my code:

      ========
      #!perl -w

      use strict;
      use SOAP::Lite

      my $server = SOAP::Lite

      ->uri('http://innovsys.com/oss/webservicesprivate/accountsreceivable')

      ->proxy('http://administrator:*****@mtsql/eLation.Web.Service/AccountsReceiv
      able.asmx')
      ->on_action(sub{sprintf '"%s/%s"', @_ });

      my $returned = $server
      ->call(SOAP::Data->name('GetAccountInfoByName')->attr({xmlns =>
      'http://innovsys.com/oss/webservicesprivate/accountsreceivable'}) =>
      SOAP::Data->name('Name')->value('Frank Bulk')->type('') );

      print $returned->valueof('//AccountID/') . "\n";
      ========
      The last line of this code does properly print the response, but I would
      like a way for a hash of the total response to be built. Here's the
      complete XML response with all the data, which you can see is not so easy to
      parse with the eyes:

      ========
      <?xml version="1.0" encoding="utf-8"?><soap:Envelope
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsi="http://www.w3.org/200
      1/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAccountInfoByNam
      eResponse xmlns="http://innovsys.com/oss/w
      ebservicesprivate/accountsreceivable"><GetAccountInfoByNameResult><xs:schema
      id="AccountsReceivableDataSet" targetNamespace="http://tempuri.
      org/AccountsReceivableDataSet.xsd"
      xmlns:mstns="http://tempuri.org/AccountsReceivableDataSet.xsd"
      xmlns="http://tempuri.org/AccountsReceivab
      leDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
      attributeFormDefault="qualifi
      ed" elementFormDefault="qualified"><xs:element
      name="AccountsReceivableDataSet" msdata:IsDataSet="true"
      msdata:UseCurrentLocale="true"><xs:c
      omplexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element
      name="WsAccountInfo"><xs:complexType><xs:sequence><xs:element name="Ac
      countID" type="xs:int" /><xs:element name="AccountCode" type="xs:string"
      /><xs:element name="AccountStatus" type="xs:string" /><xs:element n
      ame="DeliveryName" type="xs:string" minOccurs="0" /><xs:element
      name="DeliveryAddressLine1" type="xs:string" minOccurs="0" /><xs:element nam
      e="DeliveryAddressLine2" type="xs:string" minOccurs="0" /><xs:element
      name="DeliveryCity" type="xs:string" minOccurs="0" /><xs:element name=
      "LastPaymentDate" type="xs:dateTime" minOccurs="0" /><xs:element
      name="LastPaymentAmount" type="xs:decimal" minOccurs="0" /><xs:element name
      ="CreditScore" type="xs:int" /><xs:element name="CreditRating"
      type="xs:string" minOccurs="0" /><xs:element name="BalanceCurrent"
      type="xs:d
      ecimal" /><xs:element name="Balance30" type="xs:decimal" /><xs:element
      name="Balance60" type="xs:decimal" /><xs:element name="Balance90" typ
      e="xs:decimal" /><xs:element name="Balance120" type="xs:decimal"
      /><xs:element name="NextBillDate" type="xs:dateTime" minOccurs="0" /><xs:el
      ement name="ServiceStartDate" type="xs:dateTime" minOccurs="0"
      /></xs:sequence></xs:complexType></xs:element><xs:element
      name="WsPhoneInfo">
      <xs:complexType><xs:sequence><xs:element name="PhoneID" type="xs:int"
      /><xs:element name="PhoneNumber" type="xs:string" /><xs:element name="
      PhoneStatus" type="xs:string" /><xs:element name="AccountID" type="xs:int"
      minOccurs="0" /></xs:sequence></xs:complexType></xs:element><xs:e
      lement name="WsAccountsByPhone"><xs:complexType><xs:sequence><xs:element
      name="AccountID" type="xs:int" minOccurs="0" /><xs:element name="Ac
      countCode" type="xs:string" minOccurs="0" /><xs:element name="Account"
      type="xs:string" minOccurs="0" /><xs:element name="AccountStatus" typ
      e="xs:string" minOccurs="0" /><xs:element name="Phone" type="xs:string"
      minOccurs="0" /><xs:element name="DeliveryAddressLine1" type="xs:str
      ing" minOccurs="0" /><xs:element name="DeliveryAddressLine2"
      type="xs:string" minOccurs="0" /><xs:element name="DeliveryCity"
      type="xs:strin
      g" minOccurs="0"
      /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType><
      xs:unique name="PK_WsAccountInfo" msdata:Primar
      yKey="true"><xs:selector xpath=".//mstns:WsAccountInfo" /><xs:field
      xpath="mstns:AccountID" /></xs:unique><xs:unique name="PK_WsPhoneInfo" m
      sdata:PrimaryKey="true"><xs:selector xpath=".//mstns:WsPhoneInfo"
      /><xs:field xpath="mstns:PhoneID" /></xs:unique><xs:keyref name="WsAccount
      InfoWsPhoneInfo" refer="PK_WsAccountInfo"><xs:selector
      xpath=".//mstns:WsPhoneInfo" /><xs:field xpath="mstns:AccountID"
      /></xs:keyref></xs:e
      lement></xs:schema><diffgr:diffgram
      xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
      xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram
      -v1"><AccountsReceivableDataSet
      xmlns="http://tempuri.org/AccountsReceivableDataSet.xsd"><WsAccountsByPhone
      diffgr:id="WsAccountsByPhone1" m
      sdata:rowOrder="0"><AccountID>12811</AccountID><AccountCode>00002866-0</Acco
      untCode><Account>Frank Bulk</Account><AccountStatus>Active</Acco
      untStatus><Phone>1234567890</Phone><DeliveryAddressLine1>123 1st. Ave
      NE</DeliveryAddressLine1><DeliveryCity>Anytown , IA 12345-1234</De
      liveryCity></WsAccountsByPhone></AccountsReceivableDataSet></diffgr:diffgram
      ></GetAccountInfoByNameResult></GetAccountInfoByNameResponse></s
      oap:Body></soap:Envelope>
      ========
    Your message has been successfully submitted and would be delivered to recipients shortly.