에 속성을 추가 할 수 있습니다 :어떻게 이런 속성을 soapVars를 만들 싶습니다 soapVars
<tag attr="xxx">yyy</tag>
가 SoapVar 생성자와이 가능하지만, XSD_ANYXML 원시 XML 문자열을 사용하지?
에 속성을 추가 할 수 있습니다 :어떻게 이런 속성을 soapVars를 만들 싶습니다 soapVars
<tag attr="xxx">yyy</tag>
가 SoapVar 생성자와이 가능하지만, XSD_ANYXML 원시 XML 문자열을 사용하지?
그것을 할 수있는 가장 좋은 방법은 다음과 같습니다
<?php
$tag['_'] = 'yyy';
$tag['attr'] = 'xxx';
$tagVar = new SoapVar($tag, SOAP_ENC_OBJECT);
?>
결과는 다음과 같습니다
<tag attr="xxx">yyy</tag>
솔루션을 찾고 많은 시간을 소비 한 후, 나는 단지이 해결 방법을 발견했다. 내 경우에 효과가있어.
/**
* 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>
XML 파서를 사용하는 것이 좋습니다. 어떤 태그 안에'RequestBase' 문자열을 대체하고 싶지 않은 경우가 있습니다. –
pcmind의 대답은 나를 위해 작동하지 않았고, 또한 당신은 PhpFiddle에서 그것을 시도하지 않은 경우. http://eosrei.net/articles/2012/01/php-soap-xml-attributes-namespaces-xmlwriter
이 완전히 내 경우에 작동합니다
나는 기본적으로 XMLWriter가와 XML을 생성이 기사에 비틀 거렸다.
와우! 어디서 찾았 니? – goorj
당신은 항상 php.net을 참조 할 수 있습니다 :) – pcmind
코멘트 섹션? :-) – goorj