/** * @param array<CuePoint> $cuePoints * @return string xml */ public static function generateXml(array $cuePoints) { $schemaType = CuePointPlugin::getApiValue(CuePointSchemaType::SERVE_API); $xsdUrl = "http://" . kConf::get('cdn_host') . "/api_v3/service/schema/action/serve/type/{$schemaType}"; $scenes = new SimpleXMLElement('<scenes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="' . $xsdUrl . '" />'); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaCuePointXmlParser'); foreach ($cuePoints as $cuePoint) { $scene = null; foreach ($pluginInstances as $pluginInstance) { $scene = $pluginInstance->generateXml($cuePoint, $scenes, $scene); } } $xmlContent = $scenes->asXML(); $xml = new KDOMDocument(); libxml_use_internal_errors(true); libxml_clear_errors(); if (!$xml->loadXML($xmlContent)) { $errorMessage = kXml::getLibXmlErrorDescription($xmlContent); throw new kCuePointException("XML is invalid:\n{$errorMessage}", kCuePointException::XML_INVALID); } $xsdPath = SchemaService::getSchemaPath($schemaType); libxml_clear_errors(); if (!$xml->schemaValidate($xsdPath)) { $errorMessage = kXml::getLibXmlErrorDescription($xmlContent); throw new kCuePointException("XML is invalid:\n{$errorMessage}", kCuePointException::XML_INVALID); } return $xmlContent; }
<?php $downloadUrl = 'http://' . kConf::get('www_host') . "/api_v3/index.php/service/schema/action/serve/type/{$schemaType}/name/{$schemaType}.xsd"; echo "Download URL: <a href=\"{$downloadUrl};\" target=\"_blank\">{$downloadUrl}</a><br/>\n"; $schemaPath = SchemaService::getSchemaPath($schemaType); $xslPath = dirname(__FILE__) . '/xsl/type.xsl'; // Load the XML source $xml = new KDOMDocument(); $xml->load($schemaPath); if ($xml->firstChild->hasAttribute('version')) { echo "Version: " . $xml->firstChild->getAttribute('version') . "<br/>\n"; } $xsl = new KDOMDocument(); $xsl->load($xslPath); // Configure the transformer $proc = new XSLTProcessor(); $proc->importStyleSheet($xsl); // attach the xsl rules echo "<br/>\n"; echo $proc->transformToXML($xml);