5.8.2 Node¶
-
enum SerdNodeType¶
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). Serd also has support for variable nodes to support some features, which are not RDF nodes.
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_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”). RFC3986
-
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. RDF 1.1 Turtle
-
enumerator SERD_VARIABLE¶
A variable node.
Value is a variable name without any syntactic prefix, like “name”, which is meaningful only within this serialisation. SPARQL 1.1 Query Language
-
enumerator SERD_LITERAL¶
-
enum SerdNodeFlag¶
Flags that describe the details of a node.
-
enumerator SERD_IS_LONG¶
Literal node should be triple-quoted.
-
enumerator SERD_HAS_DATATYPE¶
Literal node has datatype.
-
enumerator SERD_HAS_LANGUAGE¶
Literal node has language.
-
enumerator SERD_IS_LONG¶
-
typedef struct SerdNodeImpl SerdNode¶
An RDF node.
-
typedef uint32_t SerdNodeFlags¶
Bitwise OR of SerdNodeFlag values.
-
bool serd_get_boolean(const SerdNode *node)¶
Return the value of
nodeas a boolean.This will work for booleans, and numbers of any datatype if they are 0 or 1.
- Returns
The value of
nodeas abool, orfalseon error.
-
double serd_get_double(const SerdNode *node)¶
Return the value of
nodeas a double.This will coerce numbers of any datatype to double, if the value fits.
- Returns
The value of
nodeas adouble, or NaN on error.
-
float serd_get_float(const SerdNode *node)¶
Return the value of
nodeas a float.This will coerce numbers of any datatype to float, if the value fits.
- Returns
The value of
nodeas afloat, or NaN on error.
-
int64_t serd_get_integer(const SerdNode *node)¶
Return the value of
nodeas a long (signed 64-bit integer).This will coerce numbers of any datatype to long, if the value fits.
- Returns
The value of
nodeas aint64_t, or 0 on error.
-
size_t serd_get_base64_size(const SerdNode *node)¶
Return the maximum size of a decoded base64 node in bytes.
This returns an upper bound on the number of bytes that would be decoded by
serd_get_base64(). This is calculated as a simple constant-time arithmetic expression based on the length of the encoded string, so may be larger than the actual size of the data due to things like additional whitespace.
-
SerdWriteResult serd_get_base64(const SerdNode *node, size_t buf_size, void *buf)¶
Decode a base64 node.
This function can be used to decode a node created with
serd_new_base64().- Parameters
node – A literal node which is an encoded base64 string.
buf_size – The size of
bufin bytes.buf – Buffer where decoded data will be written.
- Returns
On success,
SerdStatus.SERD_SUCCESSis returned along with the number of bytes written. If the output buffer is too small, thenSerdStatus.SERD_OVERFLOWis returned along with the number of bytes required for successful decoding.
-
SerdNode *serd_node_copy(SerdAllocator *allocator, const SerdNode *node)¶
Return a deep copy of
node
-
void serd_node_free(SerdAllocator *allocator, SerdNode *node)¶
Free any data owned by
node
-
SerdNodeType serd_node_type(const SerdNode *node)¶
Return the type of a node (SERD_URI, SERD_BLANK, or SERD_LITERAL)
-
size_t serd_node_length(const SerdNode *node)¶
Return the length of the node’s string in bytes (excluding terminator)
-
SerdStringView serd_node_string_view(const SerdNode *node)¶
Return a view of the string in a node.
This is a convenience wrapper for
serd_node_string()andserd_node_length()that can be used to get both in a single call.
-
SerdURIView serd_node_uri_view(const SerdNode *node)¶
Return a parsed view of the URI in a node.
It is best to check the node type before calling this function, though it is safe to call on non-URI nodes. In that case, it will return a null view with all fields zero.
Note that this parses the URI string contained in the node, so it is a good idea to keep the value if you will be using it several times in the same scope.
-
SerdNodeFlags serd_node_flags(const SerdNode *node)¶
Return the flags (string properties) of a node.
-
const SerdNode *serd_node_datatype(const SerdNode *node)¶
Return the datatype of the literal node, if present.
-
const SerdNode *serd_node_language(const SerdNode *node)¶
Return the language tag of the literal node, if present.
-
int serd_node_compare(const SerdNode *a, const SerdNode *b)¶
Compare two nodes.
Returns less than, equal to, or greater than zero if
ais less than, equal to, or greater thanb, respectively. NULL is treated as less than any other node.Nodes are ordered first by type, then by string value, then by language or datatype, if present.