0

I am working on a nusoap client call, for a web service, I am using nusoap.php last library.

When I made the XML structure I use this:

$string =<<<XML<?xml version='1.0'?><cliente> <nombre>$posts['nombre']</nombre> <apellido>$posts['apellido']</apellido> <calle>$posts['direccion']</calle> <altura>$posts['altura']</altura> <pisodto>$posts['pisodto']</pisodto> <localidad>$posts['localidad']</localidad> <provincia>$posts['provincia']</provincia> <partido>$posts['partido']</partido> <telefono>$posts['telefono']</telefono> <celular>$posts['celular']</celular> <email>$posts['email']</email> </cliente> XML; 

But for some reason WAMP doesn't like it and I always get this error:

Parse error: syntax error, unexpected '<<' (T_SL) in G:\wamp\www\bsmart\PHPtoXML2\enviarxml.php on line 98

Here is the full code

date_default_timezone_set('America/Argentina/Buenos_Aires'); require_once 'assets/clases/nusoap/nusoap.php'; $wsdl = "http://ws.maxirest.com/wsclientes/wscli06896.php?WSDL"; $cliente = new nusoap_client($wsdl); $produccion = false; //Cambiar a verdadero por producction $endpoint = $wsdl; //print_r($_POST); $posts = $_POST; if ($produccion == false) { $posts['nombre'] = $posts['apellido'] = $posts['direccion'] = $posts['pisodto'] = $posts['localidad'] = $posts['partido'] = $posts['provincia'] = $posts['telefono'] = $posts['celular'] = $posts['altura'] = $posts['email'] = "PRUEBA"; } $string =<<<XML<?xml version='1.0'?><cliente> <nombre>$posts['nombre']</nombre> <apellido>$posts['apellido']</apellido> <calle>$posts['direccion']</calle> <altura>$posts['altura']</altura> <pisodto>$posts['pisodto']</pisodto> <localidad>$posts['localidad']</localidad> <provincia>$posts['provincia']</provincia> <partido>$posts['partido']</partido> <telefono>$posts['telefono']</telefono> <celular>$posts['celular']</celular> <email>$posts['email']</email> </cliente> XML; $param = array('cXml' => $string, 'clave' => "123ClubMilaMREST5"); $client = new nusoap_client($wsdl);//Ruta donde se encuentra nuestro servicio para consumirlo $resultado = $client->call('AltaSolicitud',$param); //Codigo para debugear y ver la respuesta y posibles errores, comentar cuando se comprueba que está correcto el servicio y la llamada $err = $client->getError(); if ($err) { echo '<p><b>Constructor error: ' . $err . '</b></p>'; } echo '<h2>Request</h2>'; echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; echo '<h2>Response</h2>'; echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; echo htmlspecialchars($client->response, ENT_QUOTES) . '</b></p>'; echo '<p><b>Debug: <br>'; echo htmlspecialchars($client->debug_str, ENT_QUOTES) .'</b></p>'; //Comentar hasta aquí if($client->fault) { echo "FAULT: <p>Code: (".$client->faultcode.")</p>"; echo "String: ".$client->faultstring; } else { var_dump ($resultado); } 

I think maybe a library could be missing, but I am not sure, any help would be very appreciated, thanks in advance.

6
  • Actually that just a PHP syntax error so its not the fault of WAMPServer, its a typo Commented Jun 29, 2015 at 16:51
  • That, and the $posts variable chaining like that is wrong. Commented Jun 29, 2015 at 16:54
  • Not the type of RAILS, we was lookin' for, eh Sam? - @JayBlanchard Commented Jun 29, 2015 at 16:56
  • @JayBlanchard Why is the $posts chaining wrong. That should set all to PRUEBA I know its nonsence as in that code $produccion will always be == false but? Commented Jun 29, 2015 at 17:00
  • Yes, you're right @RiggsFolly but I don't think the OP wants to set them all the same. Do you? Commented Jun 29, 2015 at 17:01

1 Answer 1

2

You need to have a line-break after XML.

$string = <<<XML ^ line break mandatory, it marks the end of the "XML" mark (heredoc identifier). 

See the PHP Heredoc String Syntax for the important details.

Additionally array string keys inside strings aren't quoted.

Full example:

$string = <<<XML <?xml version='1.0'?><cliente> <nombre>$posts[nombre]</nombre> <apellido>$posts[apellido]</apellido> <calle>$posts[direccion]</calle> <altura>$posts[altura]</altura> <pisodto>$posts[pisodto]</pisodto> <localidad>$posts[localidad]</localidad> <provincia>$posts[provincia]</provincia> <partido>$posts[partido]</partido> <telefono>$posts[telefono]</telefono> <celular>$posts[celular]</celular> <email>$posts[email]</email> </cliente> XML; 
Sign up to request clarification or add additional context in comments.

8 Comments

For some reason, now the error now marks where the post variables are
Well you fixed the first error so it has now moved on to the next one. There you go, Jay has fixed the next error for you already
Amm where? Thanks for your answer
@Ricardo Rios: Please see the updated anwer, it wasn't precise earlier. Try to understand the error message that is given. PHP error messages are not always perfect (to say at least) but they give some hints :)
I see now, for some reason now is changing the < > tags of the xml to this &lt; like nombre&gt;PRUEBA&lt;/nombre&gt; instead of <nombre>PRUEBA</nombre>
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.