여러 타입의 SOAP Data를 만들어 내는데 사용한다.
$elem1 = SOAP::Data->new(name => 'idx', value => 5);
$elem2 = SOAP::Data->name('idx' => 5);
$elem3 = SOAP::Data->name('idx')->value(5);
위의 3개의 예제는 모두 같은 값이다.
<foo>
<bar>123</bar>
</foo>
의 구현을 위해서는 아래의 예제를 사용하면 된다.
SOAP::Data->name('foo' => \SOAP::Data->value(
SOAP::Data->name('bar' => '123')));
Array 예제
$elem1 = SOAP::Data->name('item' => 123)->type('SomeObject');
$elem2 = SOAP::Data->name('item' => 456)->type('SomeObject');
push(@array,$elem1);
push(@array,$elem2);
my $client = SOAP::Lite
->readable(1)
->uri($NS)
->proxy($HOST);
$temp_elements = SOAP::Data
->name("CallDetails" => \SOAP::Data->value(
SOAP::Data->name("elem1" => 'foo'),
SOAP::Data->name("elem2" => 'baz'),
SOAP::Data->name("someArray" => \SOAP::Data->value(
SOAP::Data->name("someArrayItem" => @array)
->type("SomeObject"))
)->type("ArrayOf_SomeObject") ))
->type("SomeObject");
$response = $client->someMethod($temp_elements);
결과물 확인
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:namesp2="http://namespaces.soaplite.com/perl"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<namesp1:someMethod xmlns:namesp1="urn:TemperatureService">
<CallDetails xsi:type="namesp2:SomeObject">
<elem1 xsi:type="xsd:string">foo</elem1>
<elem2 xsi:type="xsd:string">baz</elem2>
<someArray xsi:type="namesp2:ArrayOf_SomeObject">
<item xsi:type="namesp2:SomeObject">123</bar>
<item xsi:type="namesp2:SomeObject">456</bar>
</someArray>
</CallDetails>
</namesp1:test>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML 자체로 Data를 만들어 낼 수도 있음
$xml_content = "<foo><bar>123</bar></foo>";
$elem = SOAP::Data->type('xml' => $xml_content);
댓글 없음:
댓글 쓰기