You are here

protected function EasyRdf_Serialiser_RdfXml::rdfxmlObject in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php \EasyRdf_Serialiser_RdfXml::rdfxmlObject()

Protected method to serialise an object node into an XML object @ignore

1 call to EasyRdf_Serialiser_RdfXml::rdfxmlObject()
EasyRdf_Serialiser_RdfXml::rdfxmlResource in vendor/easyrdf/easyrdf/lib/EasyRdf/Serialiser/RdfXml.php
Protected method to serialise a whole resource and its properties @ignore

File

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

Class

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

Code

protected function rdfxmlObject($property, $obj, $depth) {
  $indent = str_repeat('  ', $depth);
  if ($property[0] === ':') {
    $property = substr($property, 1);
  }
  if (is_object($obj) and $obj instanceof EasyRdf_Resource) {
    $pcount = count($obj
      ->propertyUris());
    $rpcount = $this
      ->reversePropertyCount($obj);
    $alreadyOutput = isset($this->outputtedResources[$obj
      ->getUri()]);
    $tag = "{$indent}<{$property}";
    if ($obj
      ->isBNode()) {
      if ($alreadyOutput or $rpcount > 1 or $pcount == 0) {
        $tag .= " rdf:nodeID=\"" . htmlspecialchars($obj
          ->getBNodeId()) . '"';
      }
    }
    else {
      if ($alreadyOutput or $rpcount != 1 or $pcount == 0) {
        $tag .= " rdf:resource=\"" . htmlspecialchars($obj
          ->getURI()) . '"';
      }
    }
    if ($alreadyOutput == false and $rpcount == 1 and $pcount > 0) {
      $xml = $this
        ->rdfxmlResource($obj, false, $depth + 1);
      if ($xml) {
        return "{$tag}>{$xml}{$indent}</{$property}>\n\n";
      }
      else {
        return '';
      }
    }
    else {
      return $tag . "/>\n";
    }
  }
  elseif (is_object($obj) and $obj instanceof EasyRdf_Literal) {
    $atrributes = "";
    $datatype = $obj
      ->getDatatypeUri();
    if ($datatype) {
      if ($datatype == self::RDF_XML_LITERAL) {
        $atrributes .= " rdf:parseType=\"Literal\"";
        $value = strval($obj);
      }
      else {
        $datatype = htmlspecialchars($datatype);
        $atrributes .= " rdf:datatype=\"{$datatype}\"";
      }
    }
    elseif ($obj
      ->getLang()) {
      $atrributes .= ' xml:lang="' . htmlspecialchars($obj
        ->getLang()) . '"';
    }

    // Escape the value
    if (!isset($value)) {
      $value = htmlspecialchars(strval($obj));
    }
    return "{$indent}<{$property}{$atrributes}>{$value}</{$property}>\n";
  }
  else {
    throw new EasyRdf_Exception("Unable to serialise object to xml: " . getType($obj));
  }
}