[redland-dev] Serializing XML Literals

Jason Johnston redland at lojjic.net
Sun Mar 2 23:01:13 GMT 2003


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:

------------------
# Create storage and model:
my $storage=3Dnew RDF::Redland::Storage("hashes", "test",
"new=3D'yes',hash-type=3D'bdb',dir=3D'.'");
die "Failed to create RDF::Redland::Storage\n" unless $storage;
my $model=3Dnew RDF::Redland::Model($storage, "");
die "Failed to create RDF::Redland::Model for storage\n" unless $model;

# Add a statement with XML Literal value:
my $subj =3D RDF::Redland::Node->new_from_uri_string("http://lojjic.net")=
;
my $pred =3D
RDF::Redland::Node->new_from_uri_string("http://lojjic.net/NS/rdf#content=
");
my $obj =3D  RDF::Redland::Node->new_from_literal("<p>This is well-formed
<acronym title=3D\"eXtensible Markup Language\">XML</acronym>.</p>", "en"=
, 1);
$model->add($subj, $pred, $obj);

# Serialize it to a file:
my $serializer=3Dnew RDF::Redland::Serializer("rdfxml");
	die "Failed to find serializer\n" if !$serializer;
$serializer->serialize_model_to_file("test-out.rdf", undef, $model);

# Clean up:
$serializer=3Dundef;
$storage=3Dundef;
$model=3Dundef;
---------------------

Serializes to:

---------------------
<?xml version=3D"1.0" encoding=3D"utf-8"?>
<rdf:RDF xmlns:rdf=3D"http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   <rdf:Description rdf:about=3D"http://lojjic.net">
     <ns0:content xmlns:ns0=3D"http://lojjic.net/NS/rdf#"
xml:lang=3D"`=F1=04=08=90=C1=0F=085" rdf:datatype=3D"=08=90=C1=0F=085">&l=
t;p&gt;This is well-formed
&lt;acronym title=3D"eXtensible Markup
Language"&gt;XML&lt;/acronym&gt;.&lt;/p&gt;</ns0:content>
   </rdf:Description>
</rdf:RDF>
---------------------

The same also happens when the Model is originally parsed from an
RDF-XML source (latest Raptor) instead of created manually.

Any idea what's going on here?  It seems that the Serializer shouldn't
even get to the codepath that writes out rdf:datatype
(rdf_serializer_rdfxml.c line 252+) if the Literal is_wf_xml.

Thanks in advance.

--Jason





More information about the redland-dev mailing list