You are here

protected function EasyRdf_Serialiser_RdfXml::rdfxmlResource in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php \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 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 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php
Method to serialise an EasyRdf_Graph to RDF/XML

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php, line 124

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
        ->getBNodeId()) . '"';
    }
  }
  else {
    $xml .= ' rdf:about="' . htmlspecialchars($res
      ->getUri()) . '"';
  }
  $xml .= ">\n";
  if ($res instanceof EasyRdf_Container) {
    foreach ($res as $item) {
      $xml .= $this
        ->rdfxmlObject('rdf:li', $item, $depth + 1);
    }
  }
  else {
    foreach ($properties as $property) {
      $short = EasyRdf_Namespace::shorten($property, true);
      if ($short) {
        $this
          ->addPrefix($short);
        $objects = $res
          ->all("<{$property}>");
        if ($short == 'rdf:type' && $type != 'rdf:Description') {
          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;
}