protected function EasyRdf_Serialiser_RdfXml::rdfxmlResource

Protected method to serialise a whole resource and its properties @ignore

2 calls to EasyRdf_Serialiser_RdfXml::rdfxmlResource()
EasyRdf_Serialiser_RdfXml::rdfxmlObject in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php
Protected method to serialise an object node into an XML object @ignore
EasyRdf_Serialiser_RdfXml::serialise in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php
Method to serialise an EasyRdf_Graph to RDF/XML

File

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

Class

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

Code

protected function rdfxmlResource($res, $showNodeId, $depth = 1) {

  // Keep track of the resources we have already serialised
  if (isset($this->outputtedResources[$res
    ->getUri()])) {
    return '';
  }
  else {
    $this->outputtedResources[$res
      ->getUri()] = true;
  }

  // If the resource has no properties - don't serialise it
  $properties = $res
    ->propertyUris();
  if (count($properties) == 0) {
    return '';
  }
  $type = $res
    ->type();
  if ($type) {
    $this
      ->addPrefix($type);
  }
  else {
    $type = 'rdf:Description';
  }
  $indent = str_repeat('  ', $depth);
  $xml = "\n{$indent}<{$type}";
  if ($res
    ->isBNode()) {
    if ($showNodeId) {
      $xml .= ' rdf:nodeID="' . htmlspecialchars($res
        ->getNodeId()) . '"';
    }
  }
  else {
    $xml .= ' rdf:about="' . htmlspecialchars($res
      ->getUri()) . '"';
  }
  $xml .= ">\n";
  foreach ($properties as $property) {
    $short = EasyRdf_Namespace::shorten($property, true);
    if ($short) {
      $this
        ->addPrefix($short);
      $objects = $res
        ->all("<{$property}>");
      if ($short == 'rdf:type') {
        array_shift($objects);
      }
      foreach ($objects as $object) {
        $xml .= $this
          ->rdfxmlObject($short, $object, $depth + 1);
      }
    }
    else {
      throw new EasyRdf_Exception("It is not possible to serialse the property " . "'{$property}' to RDF/XML.");
    }
  }
  $xml .= "{$indent}</{$type}>\n";
  return $xml;
}