View Source RDF.XML.Encoder (RDF-XML.ex v1.0.0)

An encoder for RDF/XML serializations of RDF.ex data structures.

As for all encoders of RDF.Serialization.Formats, you normally won't use these functions directly, but via one of the write_ functions on the RDF.XML format module or the generic RDF.Serialization module.



  • :base: : Allows to specify the base URI to be used for a xml:base declaration. If not specified the one from the given graph is used or if there is also none specified for the graph the RDF.default_base_iri/0.

  • :prefixes: Allows to specify the prefixes to be used as a RDF.PrefixMap or anything from which a RDF.PrefixMap can be created with If not specified the ones from the given graph are used or if these are also not present the RDF.default_prefixes/0.

  • :implicit_base: Allows to specify that the used base URI should not be encoded in the generated serialization (default: false).

  • :use_rdf_id: Allows to determine if rdf:ID should be used when possible. You can either provide a boolean value or a function which should return a boolean value for a given RDF.Description. (default: false)

  • :producer: This option allows you to provide a producer function, which will get the input data (usually a RDF.Graph) and should produce a stream of the descriptions to be encoded. This allows you to control the order of the descriptions, apply filters etc.

      ...>   EX.S1 |> EX.p1(EX.O1),
      ...>   EX.S2 |> EX.p2(EX.O2),
      ...> ])
      ...> |> RDF.XML.write_string!(
      ...>     prefixes: [ex: EX],
      ...>     producer: fn graph ->
      ...>       {first, rest} = RDF.Graph.pop(graph, EX.S2)
      ...>       Stream.concat([first], RDF.Graph.descriptions(rest))
      ...>     end)
      ~S(<?xml version="1.0" encoding="utf-8"?><rdf:RDF xmlns:ex=""><rdf:Description rdf:about=""><ex:p2 rdf:resource=""/></rdf:Description><rdf:Description rdf:about=""><ex:p1 rdf:resource=""/></rdf:Description></rdf:RDF>)

Link to this section Summary


Encodes the given RDF data structure to a RDF/XML string.

Encodes the given RDF data structure to a RDF/XML stream.

Link to this section Functions

Link to this function

encode(data, opts \\ [])

View Source
@spec encode(
) :: {:ok, String.t()} | {:error, any()}

Encodes the given RDF data structure to a RDF/XML string.

The result is returned in an :ok tuple or an :error tuple in case of an error.

For a description of the available options see the module documentation.

Link to this function

stream(data, opts \\ [])

View Source
@spec stream(
) :: Enumerable.t()

Encodes the given RDF data structure to a RDF/XML stream.

By default the RDF/XML stream will emit single line strings for each of the descriptions in the given data. But you can also receive the serialized RDF/XML description as IO lists aka iodata by setting the :mode option to :iodata.

For a description of the other available options see the module documentation.