I have a loaded an RDF::Redland::Model
parsed from an RDF/XML document and I want to add tag <foaf::nick>
in it. How can I do it?
Update:
This is my code so far:
my $st = RDF::Redland::Node->new_xml_literal("<foaf:nick>content</foaf:content>");
$self->{Model}->add_typed_literal_statement($st);
print $self->{Model}->to_string;
and it doesn't work. What am I doing wrong?
RDF models don't contain tags (or even XML elements); an RDF model is a set of triples of the form
subject predicate object
. foaf:nick is a property that relates a foaf:Person to a nickname. Based on the title of your question, it sounds like that what you want to do is add a triplesomething foaf:nick somenick
to the model. In this case, the documentation for RDF::Redland::Model indicates that what you'll want is eitheradd
oradd_typed_literal_statement
:In the first case, it appears that you'd need to create a RDF::Redland::Node to represent the literal string that is the nickname. There is a constructor that take a string argument In the second case, which is probably easier, you can just use the string directly.
Edit
Now that you've posted your code, the particular issue becomes clearer, though you still haven't mentioned what's actually going wrong.
First, if I understand what you're trying to do, the XML content that you've used isn't well formed, as the opening and closing tags don't match (
nick
is notcontent
). More problematically, this isn't how RDF works. RDF is a graph-oriented representation, where the basic concept is a statement of the formand an RDF graph, or model, is a set of these. Viewing each statement as a directed labelled edge from subject to object, we obtain a graph. RDF models can be serialized in a number of formats, one of which is RDF/XML, which is also the one that you're working with. However, as I've pointed out in this answer, the point of an RDF API is to let you work with the statements of an RDF graph, and to not be concerned with the particular serialization of the graph.
It sounds like you want to add a statement
to the graph, for some subject which you haven't identified. According to the documentation that I linked to and quoted above,
add_typed_literal_statement
takes three arguments, not one, and the third argument should be a string. Your second line should look something like:where
$subject
and$foafNick
are URI Nodes. E.g., you might do this (untested):to add the triple
to the model.