[redland-dev] Serializing XML Literals

Dave Beckett dave.beckett at bristol.ac.uk
Mon Mar 3 14:56:50 GMT 2003


>>>Jason Johnston said:
> 
> There seems to be a problem when using Literal XML values (latest
> release, RPM build); the RDF-XML serializer outputs xml:lang and
> rdf:datatype attributes with gibberish values (non-UTF-8 characters that
> make the XML unparseable), and escapes the XML content instead of
> writing it out verbatim.  For instance, the following Perl code:

<snip/>  Yeah - I confirm this.

This was a really dumb error in the C library, which unfortunately
isn't something you can work around without a recompile.

I include a patch that fixes it.


However, I've also noticed that you used method
RDF::Redland::Model::add() which has a different Perl bug I've just
fixed.  For a short term fix, if you change:
  $model->add($subj, $pred, $obj);
to this:
  my $statement=RDF::Redland::Statement->new_from_nodes($subj, $pred, $obj);
  $model->add_statement($statement);
then it works.


I've also noticed other dumb datatypes stuff in serializing to
ntriples - it totally ignores datatypes!  Works with rdf/xml though,
with this fix.

Dave


Index: librdf/rdf_node.c
===================================================================
*** librdf/rdf_node.c	2 Jan 2003 00:56:15 -0000	1.62
--- librdf/rdf_node.c	3 Mar 2003 14:07:07 -0000	1.64
***************
*** 1057,1063 ****
          strcpy((char*)buffer, (const char*)string);
          buffer += string_length+1;
          if(datatype_uri_length) {
!           strcpy((char*)buffer, (const char*)node->value.literal.datatype_uri);
            buffer += datatype_uri_length+1;
          }
          if(language_length)
--- 1057,1063 ----
          strcpy((char*)buffer, (const char*)string);
          buffer += string_length+1;
          if(datatype_uri_length) {
!           strcpy((char*)buffer, datatype_uri_string);
            buffer += datatype_uri_length+1;
          }
          if(language_length)
***************
*** 1180,1193 ****
        language_length=buffer[5];
  
        total_length= 6 + string_length + 1; /* +1 for \0 at end */
-       if(language_length) {
-         language = buffer + total_length;
-         total_length += language_length+1;
-       }
        if(datatype_uri_length) {
          datatype_uri_string = buffer + total_length;
          total_length += datatype_uri_length+1;
        }
  
        if(datatype_uri_string)
          datatype_uri=librdf_new_uri(node->world, datatype_uri_string);
--- 1180,1193 ----
        language_length=buffer[5];
  
        total_length= 6 + string_length + 1; /* +1 for \0 at end */
        if(datatype_uri_length) {
          datatype_uri_string = buffer + total_length;
          total_length += datatype_uri_length+1;
        }
+       if(language_length) {
+         language = buffer + total_length;
+         total_length += language_length+1;
+       }
  
        if(datatype_uri_string)
          datatype_uri=librdf_new_uri(node->world, datatype_uri_string);



More information about the redland-dev mailing list