eRDF Parser (v1)

This class creates an array of triples from eRDF-enhanced HTML.

Setup

Simply include the parser class:
include_once("path/to/arc/ARC_erdf_parser.php");

Instantiation

The parser can be instantiated with an array of (optional) parameters:
  • base
  • encoding (Expected encoding of the parsed document or data. Set to "auto" for auto-discovery)
  • proxy_host
  • proxy_port
  • headers (an array of HTTP headers)
  • save_data (parsed RDF/XML chunks will be stored in a variable during parsing)
e.g.
$args = array(
  "encoding" => "auto"
);
$parser = new ARC_erdf_parser($args);

Parsing

There are three different methods for parsing:
  • parse_web_file($url)
  • parse_file ($path)
  • parse_data ($data)
The method result differs from the RDF/XML parser one. The eRDF parser returns an array that contains values for the keys "error" and "result". To get at the triples, the get_triple_infos method has to be called after parsing:
$url = "http://www.example.com/data.html";
$pre_result = $parser->parse_web_file($url);
if (!$pre_result['error']) {
  $result = $parser->get_triple_infos();
  echo "found " . count($result["triples"]) . " triples";
}

Generating RDF/XML from the extracted triples

$parser->parse_web_file($url);
$rdfxml = $parser->get_rdfxml();