You are here

function ARC_rdfxml_parser::handle_open_4 in Taxonomy import/export via XML 6

Same name and namespace in other branches
  1. 5.2 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::handle_open_4()
  2. 5 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::handle_open_4()
  3. 6.2 arc/ARC_rdfxml_parser.php \ARC_rdfxml_parser::handle_open_4()
1 call to ARC_rdfxml_parser::handle_open_4()
ARC_rdfxml_parser::handle_open in arc/ARC_rdfxml_parser.php

File

arc/ARC_rdfxml_parser.php, line 567

Class

ARC_rdfxml_parser

Code

function handle_open_4($tag, $attrs) {
  $cur_s = array();
  $prev_s =& $this->subjs[$this->s_count - 1];

  /* base */
  if ($xml_base = @$attrs["http://www.w3.org/XML/1998/namespace base"]) {
    $cur_s["xml_base"] = $this
      ->calc_base($xml_base);
  }
  elseif ($p_xml_base = @$prev_s["p_xml_base"]) {
    $cur_s["xml_base"] = $p_xml_base;
  }
  elseif ($xml_base = @$prev_s["xml_base"]) {
    $cur_s["xml_base"] = $xml_base;
  }
  else {

    /* top level node */
    $cur_s["xml_base"] = $this->xml_base;
  }

  /* lang */
  if ($xml_lang = @$attrs["http://www.w3.org/XML/1998/namespace lang"]) {
    $cur_s["xml_lang"] = $xml_lang;
  }
  elseif ($p_xml_lang = @$prev_s["p_xml_lang"]) {
    $cur_s["xml_lang"] = $p_xml_lang;
  }
  elseif ($xml_lang = @$prev_s["xml_lang"]) {
    $cur_s["xml_lang"] = $xml_lang;
  }
  else {

    /* top level node */
    $cur_s["xml_lang"] = $this->xml_lang;
  }

  /* rdf:ID */
  if ($rdf_id = @$attrs["http://www.w3.org/1999/02/22-rdf-syntax-ns# ID"]) {
    $cur_s["type"] = "uri";

    //$cur_s["uri"]=$this->full_base."#".$rdf_id;
    $cur_s["uri"] = $this
      ->calc_uri($cur_s, $rdf_id, "ID");
  }
  elseif (isset($attrs["http://www.w3.org/1999/02/22-rdf-syntax-ns# about"])) {
    $cur_s["type"] = "uri";
    $uri = $attrs["http://www.w3.org/1999/02/22-rdf-syntax-ns# about"];
    $cur_s["uri"] = $this
      ->calc_uri($cur_s, $uri, "about");
  }
  else {
    $cur_s["type"] = "bnode";

    /* rdf:nodeID */
    if ($rdf_nodeID = @$attrs["http://www.w3.org/1999/02/22-rdf-syntax-ns# nodeID"]) {
      $cur_s["bnode_id"] = "_:" . $rdf_nodeID;
    }
    else {

      /* create bnode_id */
      $cur_s["bnode_id"] = $this
        ->create_bnode_id();
    }
  }

  /* Collection */
  if (@$prev_s["coll"] || @$prev_s["is_list"]) {

    /* collection is not empty || cur_s is next entry in collection */
    $list_bnode_id = $this
      ->create_bnode_id();
    $list = array(
      "type" => "bnode",
      "bnode_id" => $list_bnode_id,
    );
    if ($prev_p = @$prev_s["cur_p"]) {
      $this
        ->add_triple($prev_s, $prev_s["cur_p"], $list);
    }
    else {
      $this
        ->add_triple($prev_s, "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", $list);
    }
    $list["is_list"] = true;
    $this
      ->push_s($list);

    /* cur_s is first */
    $this
      ->add_triple($list, "http://www.w3.org/1999/02/22-rdf-syntax-ns#first", $cur_s);
    $cur_s["in_list"] = true;
    $this
      ->push_s($cur_s);
    $this->state = 2;
  }
  else {
    $this
      ->add_triple($prev_s, $prev_s["cur_p"], $cur_s);
    $this
      ->push_s($cur_s);
    $this->state = 2;
  }

  /* typed node */
  if ($tag != "http://www.w3.org/1999/02/22-rdf-syntax-ns# Description") {
    $this
      ->add_triple($cur_s, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", array(
      "type" => "uri",
      "uri" => str_replace(" ", "", $tag),
    ));
  }

  /* (additional) typing attr */
  if ($rdf_type = @$attrs["http://www.w3.org/1999/02/22-rdf-syntax-ns# type"]) {
    $this
      ->add_triple($cur_s, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", array(
      "type" => "uri",
      "uri" => $rdf_type,
    ));
  }

  /* Seq|Bag|Alt */
  $cur_s["li_count"] = 0;

  /* rdf:li elements can exist in any description element */
  if ($tag === "http://www.w3.org/1999/02/22-rdf-syntax-ns# Seq" || $tag === "http://www.w3.org/1999/02/22-rdf-syntax-ns# Bag" || $tag === "http://www.w3.org/1999/02/22-rdf-syntax-ns# Alt") {
    $cur_s["sba"] = true;
  }

  /* any other attrs (qualified, but not from rdf skip_terms or xml namespace) */
  $cur_lang = $this
    ->get_cur_lang($cur_s);
  foreach ($attrs as $k => $v) {
    if (strpos($k, "http://www.w3.org/XML/1998/namespace") === false && strpos($k, " ") !== false) {
      if (strpos($k, "http://www.w3.org/1999/02/22-rdf-syntax-ns#") === false) {
        $this
          ->add_triple($cur_s, str_replace(" ", "", $k), array(
          "type" => "literal",
          "val" => $v,
          "lang" => $cur_lang,
        ));
      }
      elseif (!in_array($k, $this->skip_terms)) {

        /* add, but may warn */
        $this
          ->add_triple($cur_s, str_replace(" ", "", $k), array(
          "type" => "literal",
          "val" => $v,
          "lang" => $cur_lang,
        ));
      }
    }
  }
}