package rdf

  1. Overview
  2. Docs

Reading and writing RDF/XML.

exception Invalid_rdf of string
module SMap : Map.S with type key = string
type tree =
  1. | E of Xmlm.tag * tree list
  2. | D of string

The type of XML tree walked through to fill the graph.

val xml_of_string : string -> tree
  • raises Failure

    in case of invalid XML.

val get_first_child : tree -> (string * string) -> tree option

get_first tree tag returns the first child with tag s of the given xml tree or None if the given node has no such child.

type state = {
  1. subject : Term.term option;
  2. predicate : Iri.t option;
  3. xml_base : Iri.t;
  4. xml_lang : string option;
  5. datatype : Iri.t option;
  6. namespaces : string Iri.Map.t;
}

Type of current state when walking through the xml tree.

type global_state = {
  1. blanks : Term.blank_id SMap.t;
  2. gnamespaces : string Iri.Map.t;
}

Global state of the analysis.

val get_blank_node : Graph.graph -> global_state -> SMap.key -> Term.term * global_state
val input_node : Graph.graph -> state -> global_state -> tree -> global_state
val input_prop : Graph.graph -> state -> (global_state * int) -> tree -> global_state * int

Fill a graph from a current state, a pair (global state, li counter), and a property node.

val from_string : Graph.graph -> ?base:Iri.t -> string -> unit

Input graph from string. Default base is the graph name.

val from_file : Graph.graph -> ?base:Iri.t -> string -> unit

Same as from_string but read from the given file.

val from_input : Graph.graph -> ?base:Iri.t -> Xmlm.input -> unit

Same as from_string but read from the given Xmlm.input handle.

val from_xml : Graph.graph -> ?base:Iri.t -> tree -> unit

Same as from_string but read from the given Xml tree.

val to_string : ?compact:bool -> ?namespaces:(Iri.t * string) list -> Graph.graph -> string

Return a RDF/XML representation of the graph in a string.

  • parameter compact

    Default is true. If true and if the graph storage allows it, the returned XML is more compact, with only one node for each subject appearing in the graph triples.

val to_file : ?compact:bool -> ?namespaces:(Iri.t * string) list -> Graph.graph -> string -> unit

Same as to_string but writes to the given file.

OCaml

Innovation. Community. Security.