## RDF term (librdf_node) RDF term (librdf_node) — RDF triple component |

## Synopsis

    typedef             librdf_node;
    enum                librdf_node_type;
    librdf_node*        librdf_new_node                     (librdf_world *world);
    librdf_node*        librdf_new_node_from_uri_string     (librdf_world *world,
                                                             unsigned char *uri_string);
    librdf_node*        librdf_new_node_from_uri            (librdf_world *world,
                                                             librdf_uri *uri);
    librdf_node*        librdf_new_node_from_uri_local_name (librdf_world *world,
                                                             librdf_uri *uri,
                                                             unsigned char *local_name);
    librdf_node*        librdf_new_node_from_normalised_uri_string
                                                            (librdf_world *world,
                                                             unsigned char *uri_string,
                                                             librdf_uri *source_uri,
                                                             librdf_uri *base_uri);
    librdf_node*        librdf_new_node_from_literal        (librdf_world *world,
                                                             unsigned char *string,
                                                             const char *xml_language,
                                                             int is_wf_xml);
    librdf_node*        librdf_new_node_from_typed_literal  (librdf_world *world,
                                                             unsigned char *value,
                                                             const char *xml_language,
                                                             librdf_uri *datatype_uri);
    librdf_node*        librdf_new_node_from_typed_counted_literal
                                                            (librdf_world *world,
                                                             unsigned char *value,
                                                             size_t value_len,
                                                             const char *xml_language,
                                                             size_t xml_language_len,
                                                             librdf_uri *datatype_uri);
    librdf_node*        librdf_new_node_from_blank_identifier
                                                            (librdf_world *world,
                                                             unsigned char *identifier);
    librdf_node*        librdf_new_node_from_node           (librdf_node *node);
    void                librdf_free_node                    (librdf_node *node);
    librdf_uri*         librdf_node_get_uri                 (librdf_node *node);
    librdf_node_type    librdf_node_get_type                (librdf_node *node);
    unsigned char*      librdf_node_get_literal_value       (librdf_node *node);
    unsigned char*      librdf_node_get_literal_value_as_counted_string
                                                            (librdf_node *node,
                                                             size_t *len_p);
    char*               librdf_node_get_literal_value_as_latin1
                                                            (librdf_node *node);
    char*               librdf_node_get_literal_value_language
                                                            (librdf_node *node);
    int                 librdf_node_get_literal_value_is_wf_xml
                                                            (librdf_node *node);
    librdf_uri*         librdf_node_get_literal_value_datatype_uri
                                                            (librdf_node *node);
    int                 librdf_node_get_li_ordinal          (librdf_node *node);
    unsigned char*      librdf_node_get_blank_identifier    (librdf_node *node);
    int                 librdf_node_is_resource             (librdf_node *node);
    int                 librdf_node_is_literal              (librdf_node *node);
    int                 librdf_node_is_blank                (librdf_node *node);
    size_t              librdf_node_encode                  (librdf_node *node,
                                                             unsigned char *buffer,
                                                             size_t length);
    librdf_node*        librdf_node_decode                  (librdf_world *world,
                                                             size_t *size_p,
                                                             unsigned char *buffer,
                                                             size_t length);
    unsigned char*      librdf_node_to_string               (librdf_node *node);
    unsigned char*      librdf_node_to_counted_string       (librdf_node *node,
                                                             size_t *len_p);
    void                librdf_node_print                   (librdf_node *node,
                                                             FILE *fh);
    int                 librdf_node_equals                  (librdf_node *first_node,
                                                             librdf_node *second_node);
    librdf_iterator*    librdf_node_static_iterator_create  (librdf_node **nodes,
                                                             int size);

## Description

The (subject, predicate, object) parts of an RDF triple.

## Details

### librdf_node

    typedef struct librdf_node_s librdf_node;

Redland node class.

### enum librdf_node_type

    typedef enum {
      LIBRDF_NODE_TYPE_UNKNOWN   = 0,  /* To catch uninitialised nodes */
      LIBRDF_NODE_TYPE_RESOURCE  = 1,  /* rdf:Resource (& rdf:Property) - has a URI */
      LIBRDF_NODE_TYPE_LITERAL   = 2,  /* rdf:Literal - has an XML string, language, XML space */
      /* node type 3 is unused at present. Do not renumber this list. */
      LIBRDF_NODE_TYPE_BLANK     = 4,  /* blank node has an identifier string */
      LIBRDF_NODE_TYPE_LAST      = LIBRDF_NODE_TYPE_BLANK
    } librdf_node_type;

Type of a redland node.

Better to check this with functions `librdf_node_is_resource()`, `librdf_node_is_literal()` or `librdf_node_is_blank()`.

`LIBRDF_NODE_TYPE_UNKNOWN` | Internal
`LIBRDF_NODE_TYPE_RESOURCE` | rdf:Resource (& rdf:Property) - has a URI
`LIBRDF_NODE_TYPE_LITERAL` | rdf:Literal - has an XML string, language, XML space
`LIBRDF_NODE_TYPE_BLANK` | blank node has an identifier string.
`LIBRDF_NODE_TYPE_LAST` | Internal

### librdf_new_node ()

    librdf_node*        librdf_new_node                     (librdf_world *world);

Constructor - create a new librdf_node object with a private identifier.

Calls librdf_new_node_from_blank_identifier(world, NULL) to construct a new redland blank node identifier and make a new librdf_node object for it.

`world` : | redland world object
Returns : | a new librdf_node object or NULL on failure

### librdf_new_node_from_uri_string ()

    librdf_node*        librdf_new_node_from_uri_string     (librdf_world *world,
                                                             unsigned char *uri_string);

Constructor - create a new librdf_node object from a URI string.

`world` : | redland world object
`uri_string` : | string representing a URI
Returns : | a new librdf_node object or NULL on failure

### librdf_new_node_from_uri ()

    librdf_node*        librdf_new_node_from_uri            (librdf_world *world,
                                                             librdf_uri *uri);

Constructor - create a new resource librdf_node object with a given URI.

`world` : | redland world object
`uri` : | librdf_uri object
Returns : | a new librdf_node object or NULL on failure

### librdf_new_node_from_uri_local_name ()

    librdf_node*        librdf_new_node_from_uri_local_name (librdf_world *world,
                                                             librdf_uri *uri,
                                                             unsigned char *local_name);

Constructor - create a new resource librdf_node object with a given URI and local name.

`world` : | redland world object
`uri` : | librdf_uri object
`local_name` : | local name to append to URI
Returns : | a new librdf_node object or NULL on failure

### librdf_new_node_from_normalised_uri_string ()

    librdf_node*        librdf_new_node_from_normalised_uri_string
                                                            (librdf_world *world,
                                                             unsigned char *uri_string,
                                                             librdf_uri *source_uri,
                                                             librdf_uri *base_uri);

Constructor - create a new librdf_node object from a URI string normalised to a new base URI.

`world` : | redland world object
`uri_string` : | string representing a URI
`source_uri` : | source URI
`base_uri` : | base URI
Returns : | a new librdf_node object or NULL on failure

### librdf_new_node_from_literal ()

    librdf_node*        librdf_new_node_from_literal        (librdf_world *world,
                                                             unsigned char *string,
                                                             const char *xml_language,
                                                             int is_wf_xml);

Constructor - create a new literal librdf_node object.

0.9.12: xml_space argument deleted

An `xml_language` cannot be used when `is_wf_xml` is non-0. If both are given, NULL is returned. If `xml_language` is the empty string, it is the equivalent to NULL.

`world` : | redland world object
`string` : | literal string value
`xml_language` : | literal XML language (or NULL, empty string)
`is_wf_xml` : | non 0 if literal is XML
Returns : | new librdf_node object or NULL on failure

### librdf_new_node_from_typed_literal ()

    librdf_node*        librdf_new_node_from_typed_literal  (librdf_world *world,
                                                             unsigned char *value,
                                                             const char *xml_language,
                                                             librdf_uri *datatype_uri);

Constructor - create a new typed literal librdf_node object.

Only one of `xml_language` or `datatype_uri` may be given. If both are given, NULL is returned. If `xml_language` is the empty string, it is the equivalent to NULL.

`world` : | redland world object
`value` : | literal string value
`xml_language` : | literal XML language (or NULL, empty string)
`datatype_uri` : | URI of typed literal datatype or NULL
Returns : | new librdf_node object or NULL on failure

### librdf_new_node_from_typed_counted_literal ()

    librdf_node*        librdf_new_node_from_typed_counted_literal
                                                            (librdf_world *world,
                                                             unsigned char *value,
                                                             size_t value_len,
                                                             const char *xml_language,
                                                             size_t xml_language_len,
                                                             librdf_uri *datatype_uri);

Constructor - create a new typed literal librdf_node object.

Only one of `xml_language` or `datatype_uri` may be given. If both are given, NULL is returned. If `xml_language` is the empty string, it is the equivalent to NULL.

`world` : | redland world object
`value` : | literal string value
`value_len` : | literal string value length
`xml_language` : | literal XML language (or NULL, empty string)
`xml_language_len` : | literal XML language length (not used if `xml_language` is NULL)
`datatype_uri` : | URI of typed literal datatype or NULL
Returns : | new librdf_node object or NULL on failure

### librdf_new_node_from_blank_identifier ()

    librdf_node*        librdf_new_node_from_blank_identifier
                                                            (librdf_world *world,
                                                             unsigned char *identifier);

Constructor - create a new blank node librdf_node object from a blank node identifier.

If no identifier string is given, creates a new internal identifier and assigns it.

`world` : | redland world object
`identifier` : | blank node identifier or NULL
Returns : | new librdf_node object or NULL on failure

### librdf_new_node_from_node ()

    librdf_node*        librdf_new_node_from_node           (librdf_node *node);

Copy constructor - create a new librdf_node object from an existing librdf_node object.

`node` : | librdf_node object to copy
Returns : | a new librdf_node object or NULL on failure

### librdf_free_node ()

    void                librdf_free_node                    (librdf_node *node);

Destructor - destroy an librdf_node object.

`node` : | librdf_node object

### librdf_node_get_uri ()

    librdf_uri*         librdf_node_get_uri                 (librdf_node *node);

Get the URI for a node object.

Returns a pointer to the URI object held by the node, it must be copied if it is wanted to be used by the caller.

`node` : | the node object
Returns : | URI object or NULL if node has no URI.

### librdf_node_get_type ()

    librdf_node_type    librdf_node_get_type                (librdf_node *node);

Get the type of the node.

`node` : | the node object
Returns : | the node type

### librdf_node_get_literal_value ()

    unsigned char*      librdf_node_get_literal_value       (librdf_node *node);

Get the string literal value of the node.

Returns a pointer to the literal value held by the node, it must be copied if it is wanted to be used by the caller.

`node` : | the node object
Returns : | the literal string or NULL if node is not a literal

### librdf_node_get_literal_value_as_counted_string ()

    unsigned char*      librdf_node_get_literal_value_as_counted_string
                                                            (librdf_node *node,
                                                             size_t *len_p);

Get the string literal value of the node as a counted string.

Returns a pointer to the literal value held by the node, it must be copied if it is wanted to be used by the caller.

`node` : | the node object
`len_p` : | pointer to location to store length (or NULL)
Returns : | the literal string or NULL if node is not a literal

### librdf_node_get_literal_value_as_latin1 ()

    char*               librdf_node_get_literal_value_as_latin1
                                                            (librdf_node *node);

Get the string literal value of the node as ISO Latin-1.

Returns a newly allocated string containing the conversion of the UTF-8 literal value held by the node.

`node` : | the node object
Returns : | the literal string or NULL if node is not a literal

### librdf_node_get_literal_value_language ()

    char*               librdf_node_get_literal_value_language
                                                            (librdf_node *node);

Get the XML language of the node.

Returns a pointer to the literal language value held by the node, it must be copied if it is wanted to be used by the caller.

`node` : | the node object
Returns : | the XML language string or NULL if node is not a literal or there is no XML language defined.

### librdf_node_get_literal_value_is_wf_xml ()

    int                 librdf_node_get_literal_value_is_wf_xml
                                                            (librdf_node *node);

Get the XML well-formness property of the node.

`node` : | the node object
Returns : | 0 if the XML literal is NOT well formed XML content, or the node is not a literal

### librdf_node_get_literal_value_datatype_uri ()

    librdf_uri*         librdf_node_get_literal_value_datatype_uri
                                                            (librdf_node *node);

Get the typed literal datatype URI of the literal node.

`node` : | the node object
Returns : | shared URI of the datatyped literal or NULL if the node is not a literal, or has no datatype URI

### librdf_node_get_li_ordinal ()

    int                 librdf_node_get_li_ordinal          (librdf_node *node);

Get the node li object ordinal value.

`node` : | the node object
Returns : | the li ordinal value or < 1 on failure

### librdf_node_get_blank_identifier ()

    unsigned char*      librdf_node_get_blank_identifier    (librdf_node *node);

Get the blank node identifier.

`node` : | the node object
Returns : | the identifier value

### librdf_node_is_resource ()

    int                 librdf_node_is_resource             (librdf_node *node);

Check node is a resource.

`node` : | the node object
Returns : | non-zero if the node is a resource (URI)

### librdf_node_is_literal ()

    int                 librdf_node_is_literal              (librdf_node *node);

Check node is a literal.

`node` : | the node object
Returns : | non-zero if the node is a literal

### librdf_node_is_blank ()

    int                 librdf_node_is_blank                (librdf_node *node);

Check node is a blank nodeID.

`node` : | the node object
Returns : | non-zero if the node is a blank nodeID

### librdf_node_encode ()

    size_t              librdf_node_encode                  (librdf_node *node,
                                                             unsigned char *buffer,
                                                             size_t length);

Serialise a node into a buffer.

Encodes the given node in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

If the node cannot be encoded due to restrictions of the encoding format, a redland error is generated

`node` : | the node to serialise
`buffer` : | the buffer to use
`length` : | buffer size
Returns : | the number of bytes written or 0 on failure.

### librdf_node_decode ()

    librdf_node*        librdf_node_decode                  (librdf_world *world,
                                                             size_t *size_p,
                                                             unsigned char *buffer,
                                                             size_t length);

Deserialise a node from a buffer.

Decodes the serialised node (as created by `librdf_node_encode()` ) from the given buffer.

`world` : | librdf_world
`size_p` : | pointer to bytes used or NULL
`buffer` : | the buffer to use
`length` : | buffer size
Returns : | new node or NULL on failure (bad encoding, allocation failure)

### librdf_node_to_string ()

    unsigned char*      librdf_node_to_string               (librdf_node *node);

Format the node as a string.

Note a new string is allocated which must be freed by the caller.

`node` : | the node object
Returns : | a string value representing the node or NULL on failure

### librdf_node_to_counted_string ()

    unsigned char*      librdf_node_to_counted_string       (librdf_node *node,
                                                             size_t *len_p);

Format the node as a counted string.

Note a new string is allocated which must be freed by the caller.

`node` : | the node object
`len_p` : | pointer to location to store length
Returns : | a string value representing the node or NULL on failure

### librdf_node_print ()

    void                librdf_node_print                   (librdf_node *node,
                                                             FILE *fh);

Pretty print the node to a file descriptor.

This method is for debugging and the format of the output should not be relied on.

`node` : | the node
`fh` : | file handle

### librdf_node_equals ()

    int                 librdf_node_equals                  (librdf_node *first_node,
                                                             librdf_node *second_node);

Compare two librdf_node objects for equality.

Note - for literal nodes, XML language, XML space and well-formness are presently ignored in the comparison.

`first_node` : | first librdf_node node
`second_node` : | second librdf_node node
Returns : | non 0 if nodes are equal. 0 if not-equal or failure

### librdf_node_static_iterator_create ()

    librdf_iterator*    librdf_node_static_iterator_create  (librdf_node **nodes,
                                                             int size);

Create an iterator over an array of nodes.

This creates an iterator for an existing static array of librdf_node objects. It is mostly intended for testing iterator code.

`nodes` : | static array of librdf_node objects
`size` : | size of array
Returns : | a librdf_iterator serialization of the nodes or NULL on failure