2.5 Node — Serd 0.32.10 documentation

# 2.5 Node

enum SerdType

  Type of a node.

  An RDF node, in the abstract sense, can be either a resource, literal, or a blank. This type is more precise, because syntactically there are two ways to refer to a resource (by URI or CURIE).

  There are also two ways to refer to a blank node in syntax (by ID or anonymously), but this is handled by statement flags rather than distinct node types.

  enumerator SERD_NOTHING

    The type of a nonexistent node.

    This type is useful as a sentinel, but is never emitted by the reader.

  enumerator SERD_LITERAL

    Literal value.

    A literal optionally has either a language, or a datatype (not both).

  enumerator SERD_URI

    URI (absolute or relative).

    Value is an unquoted URI string, which is either a relative reference with respect to the current base URI (e.g. “foo/bar”), or an absolute URI (e.g. “http://example.org/foo”). See also: RFC3986

  enumerator SERD_CURIE

    CURIE, a shortened URI.

    Value is an unquoted CURIE string relative to the current environment, e.g. “rdf:type”. See also: CURIE Syntax 1.0

  enumerator SERD_BLANK

    A blank node.

    Value is a blank node ID without any syntactic prefix, like “id3”, which is meaningful only within this serialisation. See also: RDF 1.1 Turtle

struct SerdNode

  A syntactic RDF node.

  const uint8_t *buf

    Value string.

  size_t n_bytes

    Size in bytes (excluding null).

  size_t n_chars

    String length (excluding null).

  SerdNodeFlags flags

    Node flags (string properties).

  SerdType type

    Node type.

SerdNode serd_node_copy(const SerdNode *node)

  Make a deep copy of `node`.

  Returns:

    a node that the caller must free with `serd_node_free()`.

bool serd_node_equals(const SerdNode *a, const SerdNode *b)

  Return true iff `a` is equal to `b`.

void serd_node_free(SerdNode *node)

  Free any data owned by `node`.

  Note that if `node` is itself dynamically allocated (which is not the case for nodes created internally by serd), it will not be freed.

SerdNode serd_node_from_string(SerdType type, const uint8_t *str)

  Make a (shallow) node from `str`.

  This measures, but does not copy, `str`. No memory is allocated.

SerdNode serd_node_from_substring(SerdType type, const uint8_t *str, size_t len)

  Make a (shallow) node from a prefix of `str`.

  This measures, but does not copy, `str`. No memory is allocated. Note that the returned node may not be null terminated.

SerdNode serd_node_new_blob(const void *buf, size_t size, bool wrap_lines)

  Create a node by serialising `buf` into an xsd:base64Binary string.

  This function can be used to make a serialisable node out of arbitrary binary data, which can be decoded using `serd_base64_decode()`.

  Parameters:

    - buf – Raw binary input data.

    - size – Size of `buf`.

    - wrap_lines – Wrap lines at 76 characters to conform to RFC 2045.

SerdNode serd_node_new_decimal(double d, unsigned frac_digits)

  Create a new node by serialising `d` into an xsd:decimal string.

  The resulting node will always contain a ‘.’, start with a digit, and end with a digit (i.e. will have a leading and/or trailing ‘0’ if necessary). It will never be in scientific notation. A maximum of `frac_digits` digits will be written after the decimal point, but trailing zeros will automatically be omitted (except one if `d` is a round integer).

  Note that about 16 and 8 fractional digits are required to precisely represent a double and float, respectively.

  Parameters:

    - d – The value for the new node.

    - frac_digits – The maximum number of digits after the decimal place.

SerdNode serd_node_new_file_uri(const uint8_t *path, const uint8_t *hostname, SerdURI *out, bool escape)

  Create a new file URI node from a file system path and optional hostname.

  Backslashes in Windows paths will be converted and ‘’ will always be percent encoded. If `escape` is true, all other invalid characters will be percent encoded as well.

  If `path` is relative, `hostname` is ignored. If `out` is not NULL, it will be set to the parsed URI.

SerdNode serd_node_new_integer(int64_t i)

  Create a new node by serialising `i` into an xsd:integer string.

SerdNode serd_node_new_relative_uri(const SerdURI *uri, const SerdURI *base, const SerdURI *root, SerdURI *out)

  Create a new node by serialising `uri` into a new relative URI.

  Parameters:

    - uri – The URI to serialise.

    - base – Base URI to make `uri` relative to, if possible.

    - root – Root URI for resolution (see `serd_uri_serialise_relative()`).

    - out – Set to the parsing of the new URI (i.e. points only to memory owned by the new returned node).

SerdNode serd_node_new_uri(const SerdURI *uri, const SerdURI *base, SerdURI *out)

  Create a new node by serialising `uri` into a new string.

  Parameters:

    - uri – The URI to serialise.

    - base – Base URI to resolve `uri` against (or NULL for no resolution).

    - out – Set to the parsing of the new URI (i.e. points only to memory owned by the new returned node).

SerdNode serd_node_new_uri_from_node(const SerdNode *uri_node, const SerdURI *base, SerdURI *out)

  Simple wrapper for `serd_node_new_uri()` to resolve a URI node.

SerdNode serd_node_new_uri_from_string(const uint8_t *str, const SerdURI *base, SerdURI *out)

  Simple wrapper for `serd_node_new_uri()` to resolve a URI string.