Re: remove namespace from xml
| From: | Frank Arensmeier | Date: | Thu, 03 Dec 2009 09:06:30 +0000 |
| Subject: | Re: remove namespace from xml | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300237@lists.php.net to get a copy of this message | ||
2 dec 2009 kl. 19.12 skrev Augusto Flavio:
Hi all, i'm trying to connect to a SOAP Server but i'm having a problem. Look the xml that i need send to the server: // THIS IS THE XML CORRECT THAT NEED BE SENT TO THE SERVER <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <CalcPrecoPrazo xmlns="http://tempuri.org/"> <nCdEmpresa>XXXXX</nCdEmpresa> <sDsSenha>XXXXXX</sDsSenha> <nCdServico>40010</nCdServico> <sCepOrigem>30840300</sCepOrigem> <sCepDestino>30840280</sCepDestino> <nVlPeso>10</nVlPeso> <nCdFormato>1</nCdFormato> <nVlComprimento>20</nVlComprimento> <nVlAltura>5</nVlAltura> <nVlLargura>10</nVlLargura <nVlDiametro>0</nVlDiametro> <sCdMaoPropria>S</sCdMaoPropria> <nVlValorDeclarado>300</nVlValorDeclarado> <sCdAvisoRecebimento>S</sCdAvisoRecebimento> </CalcPrecoPrazo> </soap:Body> </soap:Envelope> And now the xml that i'm sending to the SOAP Server. //THIS IS THE XML THAT THE PHP IS SENDING <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:CalcPrecoPrazo> // HOW CAN I REMOVE THIS NAMESPACE? ns1: <nCdEmpresa xsi:type="xsd:int">XXXXX</nCdEmpresa> <sDsSenha xsi:type="xsd:string">XXXXXX</sDsSenha> <nCdServico xsi:type="xsd:string">40096</nCdServico> <sCepOrigem xsi:type="xsd:string">30840280</sCepOrigem> <sCepDestino xsi:type="xsd:string">30840300</sCepDestino> <nVlPeso xsi:type="xsd:string">10</nVlPeso> <nCdFormato xsi:type="xsd:string">1</nCdFormato> <nVlComprimento xsi:type="xsd:string">5</nVlComprimento> <nVlAltura xsi:type="xsd:string">10</nVlAltura> <nVlLargura xsi:type="xsd:string">0</nVlLargura> <nVlDiametro xsi:type="xsd:string">300</nVlDiametro> <sCdMaoPropria xsi:type="xsd:string">N</sCdMaoPropria> <nVlValorDeclarado xsi:type="xsd:string">300</nVlValorDeclarado> <sCdAvisoRecebimento xsi:type="xsd:string">N</sCdAvisoRecebimento> </ns1:CalcPrecoPrazo> </SOAP-ENV:Body> </SOAP-ENV:Envelope> How can i remove the ns1 from the Child CalcPrecoPrazo? Some idea? //here is the php code: $client = new SoapClient(null, array('location' => $url,From the SOAP man page: [...] nico 25-Aug-2006 01:20 If you want to build a Soap Server for Microsoft Office's client (like Microsoft Office Research Service) you need to rewrite SOAP's namespaces : <?php // (...) $server = new SoapServer($wsdl, array('uri' => $uri, 'classmap' => $classmap)); $server->setClass($class); function callback($buffer) {'uri' =>"http://tempuri.org/CalcPrecoPrazo",'trace' => 1 ));$results = $client->CalcPrecoPrazo($empresaCod, $empresaSenha, $codigoFrete, $cepOrigem, $cepDestino, $peso, (int)$formatoCd, (int)$comprimento, (int)$altura, (int)$largura, (int)$VlDiametro,$codMaoPropria, (float)$valor, $codAvisoRecebimento);thanks Augusto Morais Although I never worked with SOAP so far, at least when it comes to XML namespaces, you need to explicitly set those somewhere in your code before use (which you haven't). Have you asked Google or even looked at the MAN pages? After two minutes of googling, I found this.
$s = array('<ns1:RegistrationResponse>', 'ns1:', 'xmlns:ns1="urn:Microsoft.Search"');
$r = array('<RegistrationResponse xmlns="urn:Microsoft.Search">', '', '');
return (str_replace($s, $r, $buffer));
}
ob_start('callback');
$server->handle();
ob_end_flush();
// (...)
?>
There are a complete example at this URL : http://touv.ouvaton.org/article.php3?id_article=104
[...]
I am sure there are other examples too.
/frank