$GetCategoriesRequest_vars=array();
$GetCategoriesRequest_vars['XMLNS']="urn:ebay:apis:eBLBaseComponents";
$GetCategoriesRequest_vars['DetailLevel']="ReturnAll";
$GetCategoriesRequest_vars['ErrorLanguage']="en_GB";
...
//call the function and pass the vars
$GetCategoriesCall=CreateXMLforGetCategoriesCall($GetCategoriesRequest_vars);
$response=simplexml_load_file($GetCategoriesCall);
...
function CreateXMLforGetCategoriesCall($GetCategoriesRequest_vars) {
$dom=new DOMDocument('1.0','utf-8');
$dom->formatOutput=true;
//Create the root element and namespace
$element_root=$dom->createElement('GetCategoriesRequest');
$dom->appendChild($element_root);
//set the namespace as attribute
$element_root->setAttribute("xmlns", $GetCategoriesRequest_vars['XMLNS']);
//create the DetailLevel node and populate
$element_DetailLevel=$dom->createElement('DetailLevel', $GetCategoriesRequest_vars['DetailLevel']);
$element_root->appendChild($element_DetailLevel);
...
// tell the browser the output is XML via the 'Content-Type' HTTP header
header('Content-Type: text/xml');
// display DOM document
return $dom->saveXML();
}
XML Output is
<?xml version=“1.0” encoding=“utf-8” ?>
//call the function and pass the vars
$GetCategoriesCall=CreateXMLforGetCategoriesCall($GetCategoriesRequest_vars);
$response=simplexml_load_file($GetCategoriesCall);
The function CreateXMLforGetCategoriesCall() returns an XML string, which you then pass in to simplexml_load_file(), which expects a file path/URL but is being given a string. PHP should be outputting a warning message there!
Your XML ouput looks like what the browser is displaying (in pretty colours with collapsible sections, right?). Use the “view source” feature of your browser, or output it as plain text, to see the actual output.
Whether I use text/xml or text/plain, the browser-rendered html has the indents etc.
However if I view the source with the text/xml version, it is still indented. View source with text/plain and the wrapping tags are replaced with < etc which still isn’t accepted by the Ebay web service.
Any suggestions very much appreciated. I’m very new to API stuff and don’t feel I’m making the progress I’d hoped to.
Thanks for that-I wondered whether that might be the problem. I’ve tried separating the files: get_categories.php now has…
set vars
run function which returns the xml
echo $GetCategoriesCall;
so that viewed in a browser is the rendered xml.
make_call.php contains nothing other than the line
$response=simplexml_load_file(“get_categories.php”);
but this is generating:
Warning: simplexml_load_file() [function.simplexml-load-file]: get_categories.php:75: parser error : ParsePI: PI php never end … in /home/multe/public_html/make_call.php on line 4
I’m still getting error messages but they relate to missing variables not being passed to the function so I can see how it all fits together now and what I’ve been doing wrong.
To yourself and Anthony - many thanks - really appreciated.