我正在把soap web服务从.net重写成php。默认情况下,php给我的标签是这样的:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Header><ns1:FindAllCategories/></SOAP-ENV:Header><SOAP-ENV:Body><ns1:FindAllCategoriesResponse><ns1:FindAllCategoriesResult><ns1:ArtistCategoryDto>等等。
但我需要这个:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><FindAllCategoriesResponse xmlns="http://tempuri.org/"><FindAllCategoriesResult><ArtistCategoryDto>这类似于这里的问题:PHP AND SOAP. Change envelope,但是我不想像他那样破解它。此外,我正在创建一个soap服务,它将由现有的iphone应用程序使用,而不是通过SoapClient使用PHP来使用soap服务。iphone应用程序只能解析原始的xml,我现在不能更改iphone应用程序。
发布于 2012-01-06 04:22:17
在重新阅读您想要的内容并搜索php文档之后,这里是我的解决方案和我所做的几个假设。
假设
如果我是正确的,您应该知道SOAP前缀本身并不是问题所在(您可以使用任何前缀,只要它是consistent).
你想要什么?
解决方案
<?php
// Create you parse function - Regex
function SoapServerRegexParser($input)
{
// $input contains your XML Response
// Do str_replace or preg_replace
$request = preg_replace({do replace});
//return modified output to client
return $request;
}
// OR create you parse function - Regex XML Parser
function SoapServerXMLParser($input)
{
// $input contains your XML Response
// Use any xml parser that you would like
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML($input);
//Do replacement have a looke at: DOMNode::replaceChild
//return modified output to client
return $xml->saveXML();
}
// Make php buffer all output
// Send all output to a callBack function
// Replace 'SoapServerRegexParser' with the callback function name of choice
ob_start('SoapServerRegexParser'); //buffer output and set callback function
// Create SoapServer
$server = new SoapServer('wsdlfile.wsdl');
$server->handle(); //Handle incoming request
ob_end_flush(); //Release buffer, but send through callback function first
?>这应该可以做到这一点,我还没有创建regex部分或实际的xlm节点替换,但我认为您可以自己完成
https://stackoverflow.com/questions/8650580
复制相似问题