public function EasyRdf_Serialiser_RdfXml::serialise

Method to serialise an EasyRdf_Graph to RDF/XML

Parameters

object EasyRdf_Graph $graph An EasyRdf_Graph object.:

string $format The name of the format to convert to.:

Return value

string The RDF in the new desired format.

Overrides EasyRdf_Serialiser::serialise

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php, line 184

Class

EasyRdf_Serialiser_RdfXml
Class to serialise an EasyRdf_Graph to RDF/XML with no external dependancies.

Code

public function serialise($graph, $format) {
  parent::checkSerialiseParams($graph, $format);
  if ($format != 'rdfxml') {
    throw new EasyRdf_Exception("EasyRdf_Serialiser_RdfXml does not support: {$format}");
  }

  // store of namespaces to be appended to the rdf:RDF tag
  $this->prefixes = array(
    'rdf' => true,
  );

  // store of the resource URIs we have serialised
  $this->outputtedResources = array();
  $xml = '';
  foreach ($graph
    ->resources() as $resource) {
    $xml .= $this
      ->rdfxmlResource($resource, true, 1);
  }

  // iterate through namepsaces array prefix and output a string.
  $namespaceStr = '';
  foreach ($this->prefixes as $prefix => $count) {
    $url = EasyRdf_Namespace::get($prefix);
    if (strlen($namespaceStr)) {
      $namespaceStr .= "\n        ";
    }
    $namespaceStr .= ' xmlns:' . $prefix . '="' . htmlspecialchars($url) . '"';
  }
  return "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" . "<rdf:RDF" . $namespaceStr . ">\n" . $xml . "\n</rdf:RDF>\n";
}