SOAP::SOM    
    Web Service의 SOAP Response의 값을 access하는것이 가능함
    
    $som = SOAP::SOM->new;
    my $client = SOAP::Lite
        ->readable(1)
        ->uri($NS)
        ->proxy($HOST)
    $som = $client->someMethod();
    
    위의 예제에서 여기에서 $som은 SOAP::SOM 타입 이였음 dump떠보면 알 수 있겠네..
    
    잠시 dump 예제
    ------------------------------------------
    $VAR1 = bless( {
                 '_name' => 'sign',
                 '_signature' => [],
                 '_value' => [
                               'Aries'
                             ],
                 '_attr' => {}
               }, 'SOAP::Data' );
               
    타입이 'SOAP::Data'라고 분명히 나온다.
    ------------------------------------------
    
    XML data를 바로 사용가능하게 함
    $som = SOAP::SOM->new($message_as_xml);
몇몇 메서드 들    
    match(path) 
    $som->match('/Envelope/Body/[1]'); 
    SOAP의 Body는 Envelope attribute가 시작임
    $envelope = $som->envelope; 
        몰 가져오지?
    
    $ns = $som->namespaceof('[1]'); 
        네임 스페이스
        
    $body = $som->body;
    
    
예제 1 ( xpath와 비슷한 방식 ? )
    <Envelope>
      <Body>
        <fooResponse>
          <bar>abcd</bar>
        </fooResponse>
      </Body>
    </Envelope>
    
    
    my $soap = SOAP::Lite
        ->uri($SOME_NS)
        ->proxy($SOME_HOST);
    my $som = $soap->foo();
    print $som->valueof('//fooResponse/bar');
    
    
예제 2 ( attribute를 찾는 방식 )
    <Envelope>
      <Body>
        <c2fResponse>
          <convertedTemp test="foo">98.6</convertedTemp>
        </c2fResponse>
      </Body>
    </Envelope>
    
    print "The attribute is: " . 
      $som->dataof('//c2fResponse/convertedTemp')->attr->{'test'};
    
    
예제 3 ( iterate 방식 )
    <Envelope>
      <Body>
        <catalog>
          <product>
            <title>Programming Web Service with Perl</title>
            <price>$29.95</price> 
          </product>
          <product>
            <title>Perl Cookbook</title>
            <price>$49.95</price> 
          </product>
        </catalog>
      </Body>
    </Envelope>
    
    
    for my $t ($som->valueof('//catalog/product')) {
      print $t->{title} . " - " . $t->{price} . "\n";
    }
    
예제 4 ( array의 array 처리 )
    $xml = <<END_XML;
    <foo>
      <person>
        <foo>123</foo>
        <foo>456</foo>
      </person>
      <person>
        <foo>789</foo>
        <foo>012</foo>
      </person>
    </foo>
    END_XML
    #
    # 앗 왜 여기서는 Deserializer를 사용했지?
    # $som = SOAP::SOM->new($xml); 과의 차이점은 무얼까?
    #
    my $som = SOAP::Deserializer->deserialize($xml);
    my $i = 0;
    foreach my $a ($som->dataof("//person/*")) {
        $i++;
        my $j = 0;
        foreach my $b ($som->dataof("//person/[$i]/*")) {
            $j++;
            # do something
        }
    }
 
댓글 없음:
댓글 쓰기