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

RE: [soaplite] Accessing Data within XML tag (not between two tag s)

Expand Messages
  • Byrne Reese
    As usual the response can also be found at the SOAP::Lite Solutions blog: http://www.majordojo.com/archives/2003_05.html#000016
    Message 1 of 1 , May 20, 2003
      As usual the response can also be found at the SOAP::Lite Solutions blog:

      The trick here is not to use the SOAP::SOM->valueof method, but to use the SOAP::SOM->dataof method which returns a SOAP::Data object. A SOAP::Data object provides a much more accessible API to the various tid-bits buried in an XML element. So once you have your hands on the SOAP::Data object, you then need to call the SOAP::Data->attr() subroutine. Here is what the book says:

      "Allows for the setting of arbitrary attributes on the data object. Keep in mind the requirement that any attributes not natively known to SOAP must be namespace-qualified. Also allows the setting of the object's value, if passed as a second argument to the method."

      The book makes no mention of "getting" attributes, but it is easy. If you pass a HASH reference to the attr() subroutine than you are performing a set operation, if you pass a SCALAR reference than you are performing a lookup or get operation. So to fetch an attribute's value, your code will look like this:

      $response = $client->c2f("100");
      print "The attribute is: " . $response->dataof('//c2fResponse/convertedTemp')->attr->{'test'} . "\n";
      -----Original Message-----
      From: pyuergens [mailto:pyuergens@...]
      Sent: Monday, May 19, 2003 6:01 PM
      To: soaplite@yahoogroups.com
      Subject: [soaplite] Accessing Data within XML tag (not between two tags)


      I am using SOAP::Lite as client on linux and connecting to a Windows SOAP

      I was having trouble accessing data within a tag like this:

      <attribute name="LastName" value="JONES" />

      I cannot access the value "JONES" for a LastName".

      I am able to access data between two tags like this:


      using this code:

      my $result = $soap->call($method => @params);
      print $result->valueof('//VerifySessionResponse/iwsResponse/sessionInfo/

      I would greatly appreciate any help. My perl code and the server's xml
      response are listed below.


      Paul Yuergens



      use SOAP::Lite ( +trace => all, maptype => {} );

      my $soap = SOAP::Lite
        -> uri('http://authenticate.university.edu/iws')
        -> on_action( sub{ join '/', 'http://authenticate.university.edu/iws', $_[1] })
        -> proxy('http://authenticate.university.edu/iws');

      my $header = SOAP::Header->name(wsStudentCreds => {
        password => "xxxx",
        id => "dept.university.edu"
      my @params = (
         SOAP::Data->name(ticket => $ARGV[1]),
         SOAP::Data->name(userIpAddr => $ARGV[0]),
         SOAP::Data->name(returnExtendedAttributes => 1)

      my $method = SOAP::Data->name('TrueCookie')
         ->attr({xmlns => 'http://authenticate.university.edu/ws/'});

      my $result = $soap->call($method => @params);

      if ($result->fault)
         print $result->faultstring;

         print $result->valueof('//VerifySessionResponse/iwsResponse/sessionInfo/


      <?xml version="1.0" encoding="utf-8"?>
            <VerifySessionResponse xmlns="http://university.edu/ws/">
                  <iwsResponse action="Verify" hasErrors="false" transactionId="0">
                        <sessionInfo status="Active">
                                    <attribute name="UID" value="1111111" />
                                    <attribute name="LastName" value="JONES                      " />
                                    <attribute name="FirstName" value="DAVEY                          " />
                                    <attribute name="Email" value="JONES@...                           " />
                                    <attribute name="MailCode" value="155555" />
                                    <account loginId=" " type="ACF2" status="Unknown" />
                                    <account loginId="djj" type="BobbyOnline" status="Authenticated" />
                                    <account loginId=" " type="QDB" status="Unknown" />
                                    <account loginId="" type="RACF" status="Unknown" />
                                    <account loginId="1111111" type="UID" status="PasswordResetRequired"
                              <univId> 1111111</univId>
                        </sessionInfo><errorInfo xsi:nil="true" />

      To unsubscribe from this group, send an email to:

      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
    Your message has been successfully submitted and would be delivered to recipients shortly.