2010-02-13 3 views

답변

6

그것을 할 수있는 가장 좋은 방법은 다음과 같습니다

<?php 
$tag['_'] = 'yyy'; 
$tag['attr'] = 'xxx'; 
$tagVar = new SoapVar($tag, SOAP_ENC_OBJECT); 

?> 

결과는 다음과 같습니다

<tag attr="xxx">yyy</tag> 
+0

와우! 어디서 찾았 니? – goorj

+2

당신은 항상 php.net을 참조 할 수 있습니다 :) – pcmind

+1

코멘트 섹션? :-) – goorj

1

솔루션을 찾고 많은 시간을 소비 한 후, 나는 단지이 해결 방법을 발견했다. 내 경우에 효과가있어.

/** 
* A SoapClient derived class that sets the namespace correctly in the input parameters 
*/ 

class SoapClientNS extends SoapClient { 
// return xml request 
function __doRequest($request, $location, $action, $version, $one_way = NULL) { 

    //Replace each <Typename> with <ns1:Typename> or 
    $request = str_replace('RequestBase', 'ns1:RequestBase', $request); 

    return parent::__doRequest($request, $location, $action, $version, $one_way); 
} 
} 

$client = new SoapClientNS($wsdlURL); 
$client->getAllBooks(array('RequestBase' => array('code' => 'AAAA', 'password' => '234234fdf'))); 

요청 XML은 다음과 같이이었다 :

<?xml version="1.0" encoding="UTF-8"?> 

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.travco.co.uk/trlink/xsd/country/request"> 
<env:Body> 
<ns1:getAllBooks> 
<RequestBase code="AAAA" password="234234fdf"/> 
</ns1:getAllBooks> 
</env:Body> 
</env:Envelope> 
+0

XML 파서를 사용하는 것이 좋습니다. 어떤 태그 안에'RequestBase' 문자열을 대체하고 싶지 않은 경우가 있습니다. –

관련 문제