I'm having a problem getting trying to view an xml page that i generate using SOAP and want to use as a Soap Envelope, i'm getting all the information on my browser but it gives me an error when i try to view it as an xml. MY response is as below on my DOM..
<?xml version="1.0" encoding="ISO-8859-1"?><dealsCollection><deals title_description="Anytime 200" total_cost="679.00" hardware_prices="N;"/><deals title_description="Smart S" total_cost="669.00" hardware_prices="N;"/><deals title_description="Anytime 200" total_cost="679.00" hardware_prices="N;"/></dealsCollection><?xml version="1.0" encoding="ISO-8859-1"?>
I've noticed that my response output xml declaration at the end and that is probably the one causing my problem which is as stated below.
XML Parsing Error: junk after document element Location: "http://localhost/autopage/deals/deals.php?wsdl" Line Number 1, Column 318:
My Code for generating the response is as listed below, NB: im manually calling the function to get all my deals and not using a client to get it for now. my client is going to be on Android, at the moment i just need to solve a problem im facing trying to get a proper XML output.
<?php
include("../config.php");
require_once ('../nusoap/lib/nusoap.php');
//configuring the server instance
$URL = "localhost/autopage";
$namespace = $URL . '?wsdl';
$server = new nusoap_server();
//defining the WSDL with the site namespace
$server->configureWSDL('getalldealsofsite', $namespace);
//$server->methodreturnisliteralxml = TRUE;
$server->wsdl->addComplexType(
'dataArray', // MySoapObjectArray
'complexType', 'array', '', 'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:return_array_php')), 'tns:return_array_php'
);
//registering the services
$server->register(
'getalldeals',
array('amount'=>'xsd:int'),
array('return'=>'xds:dataArray'),
$namespace,
false,
'document',
'literal',
'description '
);
getalldeals(650);
//service to get all deals
function getalldeals($price){
$sql = "select * from deals WHERE total_cost >= '".$price."'";
$q = mysql_query($sql);
header("Content-Type: text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
$result = '<dealsCollection>';
while($row = mysql_fetch_assoc($q)){
$result .= '<deals ';
$result .= 'title_description="'. parseToXML($row['title_description']) .'" ';
$result .= 'total_cost="' .parseToXML($row['total_cost']). '" ';
$result .= 'hardware_prices="' .parseToXML($row['hardware_prices']). '"';
$result .= '/>';
}
$result .= '</dealsCollection>';
echo $result;
}
function parseToXML($htmlStr){
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr); // line 11
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA);
?>
Please guys i've been struggling to solve this for the past 3 days, looking forward to getting your help. Please let me know if you need more information i will gladly provide anything requested if the question is not clear.
Thank You.
No comments:
Post a Comment