Cherries in Corinth has no reviews. Be the first to submit a review for Cherries in Corinth.
/**
* Class to handle XML
*
*/
class XML
{
/**
* Simple enough, returns an object of the XML structure
* More information: http://www.php.net/simple%20xml
*
* @param string $sXML
* @return SimpleXMLElement
*/
public static function toObject($sXML)
{
return new SimpleXMLElement($sXML);
}
/**
* This is our simple xml, only supports one level deep
*
* @param array $aData
* @param string $name
* @param SimpleXMLElement $xml
* @return string
*/
public static function fromArraySimple($aData, $sName="message", &$xml=null)
{
// Build the first XML element
if(is_null($xml))
{
$xml = new SimpleXMLElement("<{$sName}/>");
}
foreach($aData as $key => $aSubData)
{
foreach($aSubData as $value)
{
$elmt = $xml->addChild($key);
$elmt->addAttribute('value', $value);
}
}
return $xml->asXML();
}
/**
* Converts multi-dimensional array into XML
*
* @param array $aData
* @param string $name
* @param SimpleXMLElement $xml
* @return string
*/
public static function fromArray($aData, $sName="message" , &$oXml=null )
{
if(is_null($oXml))
{
$oXml = new SimpleXMLElement("<{$sName}/>");
}
foreach($aData as $key => $value)
{
if(is_array($value))
{
$oXml->addChild($key);
self::fromArray($value, $sName, $oXml->$key);
}
else
{
// $oXml->addChild($key, $value);
$oXml->addChild($key, '');
}
}
return XML::fixCDATA($oXml->asXML());
}
public static function fixCDATA($string) {
$find[] = '<![CDATA[';
$replace[] = '';
return $string = str_replace($find, $replace, $string);
}
function toArray($oSimpleXml)
{
if ($oSimpleXml instanceof SimpleXMLElement)
{
$aChildren = (array)$oSimpleXml->children();
if (empty($aChildren))
{
return (string)$oSimpleXml;
}
else
{
$aData = array();
foreach ($aChildren as $sElementName => $oNode)
{
$sElementName = (string)$sElementName;
$aData[$sElementName] = self::toArray($oNode);
}
return $aData;
}
}
elseif (is_array($oSimpleXml))
{
$aData = array();
foreach ($oSimpleXml as $sElementName => $oNode)
{
$sElementName = (string)$sElementName;
$aData[$sElementName] = self::toArray($oNode);
}
return $aData;
}
return $oSimpleXml;
}
function CData($mValue)
{
return '';
}
static public function loadContentXML($sContentFile)
{
$sContents = '';
// Open the file for ready only
$bFileOpened = fopen( $sContentFile, 'r' );
if ($bFileOpened )
{
do {
$sLineData = fread( $bFileOpened, filesize( $sContentFile) );
if ( strlen( $sLineData ) == 0 ) {
break;
}
$sContents .= $sLineData;
} while( true );
// Close the file, reading complete
fclose ( $bFileOpened );
}
// Error checking if nothing was in the file -- Might not need this
if ( strlen( $sContents ) == 0 ) {
$sContents = '
';
}
return $sContents;
} // End loadContentXML
static public function xmlToArray($xml)
{
$tree = Array();
$parser = xml_parser_create('ISO-8859-1');
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $vals, $index);
xml_parser_free($parser);
$arXMLArray[0] = '$tree';
//Loop over our vals.
for ($x = 0; $x < count($vals); $x++)
{
$sThisTag = $vals[$x]['tag'];
$sThisLevel = $vals[$x]['level'];
if (is_numeric(str_replace('NODE_','',strToUpper($sThisTag))))
$sThisTag = str_replace('NODE_','',strToUpper($sThisTag));
// IF open tag, pop onto our stack this array key.
if ($vals[$x]['type'] == 'open')
{
// Let's make sure we don't have any dup nodes @ this level.
$bOpen = false;
$iCount = 0;
// While not open, keep looking for $sThisTag_$count .
do
{
// If 0 - then no _$count .
if ($iCount == 0)
{
array_push($arXMLArray,"['$sThisTag']");
$checkString = implode('',$arXMLArray);
}
else
{
array_pop($arXMLArray);
array_push($arXMLArray,"['$sThisTag" . '_' . "$iCount']");
$checkString = implode('',$arXMLArray);
}
$checkString = "If (!isSet($checkString)) { " . '$bOpen = true; }';
eval($checkString);
$iCount ++;
} while (!$bOpen);
}
// Otherwise if its close, pop what we just pushed.
else if ($vals[$x]['type'] == 'close')
{
array_pop($arXMLArray);
}
// Else if it's a complete, push the set code onto the stack & eval
// then pop it right off.
else if ($vals[$x]['type'] == 'complete')
{
@$thisVal = $vals[$x]['value'];
// Add slashes for the eval.
$thisVal = addslashes($thisVal);
// Push our new array key & what to set it to onto the stack.
// Let's make sure we don't have any dup nodes @ this level.
$bOpen = false;
$iCount = 0;
// While not open, keep looking for $sThisTag_$iCount .
do
{
// If 0 - then no _$iCount .
if ($iCount == 0)
{
array_push($arXMLArray,"['$sThisTag']");
$checkString = implode('',$arXMLArray);
}
else
{
array_pop($arXMLArray);
array_push($arXMLArray,"['$sThisTag" . '_' . "$iCount']");
$checkString = implode('',$arXMLArray);
}
$checkString = "If (!isSet($checkString)) { " . '$open = true; }';
eval($checkString);
$iCount ++;
} while (!$open);
array_push($arXMLArray," = '$thisVal';");
// Implode our stack & eval.
$createString = implode('',$arXMLArray);
eval($createString);
//Pop the = part off of the stack.
array_pop($arXMLArray);
// Now create the eval string to strip the slashes just added.
$arrayRef = implode('',$arXMLArray);
$stripSlashString = "$arrayRef = stripSlashes($arrayRef);";
eval($stripSlashString);
//Now pop the sThisTag array ref off the stack.
array_pop($arXMLArray);
}
}
// Return the $tree created by the loop.
return $tree;
}
public static function xmlentities ( $string )
{
return str_replace ( array ( '&', '"', "'", '<', '>' ), array ( '&' , '"', ''' , '<' , '>' ), $string );
}
}
Fatal error: Class 'XML' not found in
/home/sfw/includes/BingSearchResponse.class.php on line
15