So I'm trying to do something with my atomz search engine and that is transform the results with XSLT.
I have setup atomz to give me my results as XML and I created an XSL file to go along with it. When I do a search I can take the returned xml and save it to an xml file and parse it all just fine. What i would like to do though is not read in from an .xml file but create a string that pulls the data in like the following
function getSearchResults($theUrl, $permissions){
$handle = fopen($theUrl, $permissions);
while(!feof($handle)){
$searchResults .= fread($handle, 8192);
}
fclose($handle);
return($searchResults);
}
function doTransformation($theXml, $theXsl){
$xsltproc = xslt_create();
$arguments = array(
'/_xml' => $theXml,
'/_xsl' => $theXsl
);
$parameters = null;
$result = xslt_process($xsltproc, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments, $parameters);
if (!$result) die('XSLT processing error: '.xslt_error($xsltproc));
xslt_free($xsltproc);
return $result;
}
$atomzReturn = getSearchResults("http://search.atomz.com/search/?sp-q=$mySearchQuery&sp-a=sp1003484a&sp-p=all&sp-f=ISO-8859-1", "rb");
$atomzFirstResultPos = strpos($atomzReturn, "<ResultSet>");
$atomzLastResultPos = mb_strrpos($atomzReturn, "</ResultSet>");
$atomzResults = substr($atomzReturn, $atomzFirstResultPos, $atomzLastResultPos+12-$atomzFirstResultPos);
$myXsl = getSearchResults("http://localhost/phpTest/searchTransform.xsl", "rb");
echo(doTransformation($atomzResults, $myXsl));
So what I am doing with the code is grabbing my xml content out of atomz return (stripping off the ads to be reinserted later) and trying to use that xml as my xml source. Now when I try this I get the following error
Warning: Sablotron error on line 23: XML parser error 4: not well-formed (invalid token) in /Users/itorrey/Sites/phpTest/searchTest2.php on line 24
XSLT processing error: XML parser error 4: not well-formed (invalid token)
However when I echo out the xml string it gives me valid XML. If I take that xml and save it to an .xml file and load that up it works just fine so I'm not sure what the problem is but I'm guessing it's that I'm trying to use this string and it's not liking it?
Suggestions?