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

Matching on Attributes

Expand Messages
  • Patrick
    OK - I ve now been whipped twice in three days. Seems the server i m accessing doesn t like to use XML for its real power - it returns an array whose
    Message 1 of 2 , Mar 31, 2008
    • 0 Attachment

      OK - I've now been whipped twice in three days.  Seems the server i'm accessing doesn't like to use XML for its real power - it returns an array whose attribute must be matched, then followed into the value element (i'm amazed there isn't an attribute for the value here)

      Anyway - pls check out the last couple lines of code, how do i get the "Value" element of the "Property" array where "Property" has attribute "NAME" = "name"

      I know how to do it in 3 or 4 lines by looping and matching...but it would seem that the XPATH derivative might work(?).
      I've tested a couple different permutations (backets/curlys/etc..)

      Many thanks again (i don't control the server!)

      Pat

      -----------------------------------------------------

      use SOAP::Lite;

      $XML = <<EXML;
      <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="
      http://schemas.xmlsoap.org/soap/envelope/" xmlns:
      xsd="
      http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
        <ns1:findListingsWithPhoneResponse soapenv:encodingStyle="
      http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http:/
      /integration.yellowpages.com">
         <findListingsWithPhoneReturn xsi:type="ns2:SearchResult" xmlns:ns2="
      http://data2.integration.yellowpages.com">
          <Categories soapenc:arrayType="ns2:Category[0]" xsi:type="soapenc:Array" xmlns:soapenc="
      http://schemas.xmlsoap.org/s
      oap/encoding/"/>
          <Listings soapenc:arrayType="ns2:Listing[1]" xsi:type="soapenc:Array" xmlns:soapenc="
      http://schemas.xmlsoap.org/soap
      /encoding/">
           <Listing xsi:type="ns2:Listing">
            <Properties soapenc:arrayType="ns2:Property[13]" xsi:type="soapenc:Array">
             <Property Name="name" xsi:type="ns2:Property">
              <Value xsi:type="xsd:string">Sirius Satellite Datacenter</Value>
             </Property>
             <Property Name="address" xsi:type="ns2:Property">
              <Value xsi:type="xsd:string">601 W 26th St</Value>
             </Property>
             <Property Name="city" xsi:type="ns2:Property">
              <Value xsi:type="xsd:string">New York</Value>
             </Property>
             <Property Name="state" xsi:type="ns2:Property">
              <Value xsi:type="xsd:string">NY</Value>
             </Property>
             <Property Name="zip" xsi:type="ns2:Property">
              <Value xsi:type="xsd:string">10001</Value>
             </Property>
            </Properties>
           </Listing>
          </Listings>
         </findListingsWithPhoneReturn>
        </ns1:findListingsWithPhoneResponse>
       </soapenv:Body>
      </soapenv:Envelope>
      EXML

      my $som = SOAP::Deserializer->deserialize($XML);

      #/* Loop just to test access - HELP HERE!!! */
      for my $a ($som->valueof(
      '//findListingsWithPhoneReturn/Listings/Listing/Properties/Property[@Name="name"]/Value'
      )) {
          print $a . "\n";
      }

    • Patrick
      I decided to return xml from the soap call, and then used XPath directly - seemed the prudent thing to do
      Message 2 of 2 , Apr 2, 2008
      • 0 Attachment
        I decided to return xml from the soap call, and then used XPath
        directly - seemed the prudent thing to do
      Your message has been successfully submitted and would be delivered to recipients shortly.