Hello, my question is actually
What kind off structure would I use to send xml as part off a REST service if I have most off the logic in a class. I call/include the class at the top off my php index page if it becomes clear a service is being requested.
Someone mentioned to me that a class method should not output anything. Then where should I output the xml. Outside the class?
Also I have a problem that the receiving end is saying that the declaration should start at the start off the document.
The receiving end only has these two lines in the document. I do not have code to process it yet, but this already gives an error.
<?php
$url='http://www.woonbel.nl/gps/setgpsloc';
$xml =simplexml_load_string(file_get_contents($url));
?>
I send the xml from this class as you can see, so maybe here something go's wrong, something with white lines or something else. Anyway, I need some advice how to avoid the declaration error and how to send xml if I am not supposed to do it in a method?store it in a class variable first then maybe?
<?php
class gps {
public $url;
public $test;
function __construct($url) {
$this->url = $url;
}
function invoke($methode_naam) {
switch($methode_naam){
case "test":
$this->setgpsloc();
break;
case "setgpsloc":
header('Content-type: text/xml');
$status_code = 2;
$output= "<?xml version=\"1.0\"encoding=\"utf-8\"?>\n";
$output.= "<response>\n";
$output.= "\t<status>$status_code</status>\n";
$output.= "\t<fout>Geen</fout>\n";
$output.= "</response>";
echo trim($output);
}
}//EINDE invoke
}
?>
This is how I detect if a service is requested and call the class
<?php
//WEBSERVICE SECTIE
$url = $_GET['url'];
$parts = split('/', $url); // Opslaan van delen van de aangevraagde url in $parts
$cparts=count($parts);
//if($cparts>=2){
$controller = $parts[0];
$wslijst=array("gps","gebruikers");
if(in_array($controller,$wslijst)){
include $controller .".php";
$clr = new $controller("test");
$clr->invoke($parts[1]);
exit();
}
//other code underneath for displaying normal page
?>
This is the actual error the receiving end get's
PHP Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 4: parser error : XML declaration allowed only at the start of the document in D:\Domains\tsa.nl\wwwroot\index.php on line 4 PHP Warning: simplexml_load_string() [function.simplexml-load-string]: in D:\Domains\tsa.nl\wwwroot\index.php on line 4 PHP Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in D:\Domains\tsa.nl\wwwroot\index.php on line 4
thanks, Richard