[redland-dev] serializing

Dave Beckett dave.beckett at bristol.ac.uk
Wed Aug 3 15:20:55 BST 2005


On Mon, 2005-08-01 at 20:07 -0300, Pablo wrote:
> Hello.

...

> The question is, can I get something more like the first file, or
> choose the serialization syntax in some way?

You could try using the "rdfxml-abbrev" serializer to get a prettier
output, but there are no parameters to control that output form. And, as
a warning, rdfxml-abbrev does have bugs in collapsing the output and
isn't suitable for large input files (number of triples).

On the command line:
  $ rapper -q -o rdfxml-abbrev input.rdf

gives:

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Seq rdf:about="http://www.search.net/mammals">
    <rdf:li>http://www.search.net/mammals/lion</rdf:li>
    <rdf:li>http://www.search.net/mammals/hippopotamus</rdf:li>
    <ns0:name xmlns:ns0="http://www.search.net/rdf#">Mammals</ns0:name>
  </rdf:Seq>
  <rdf:Description rdf:about="http://www.search.net/mammals/lion">
    <ns1:name xmlns:ns1="http://www.search.net/rdf#">Lion</ns1:name>
  </rdf:Description>
  <rdf:Description
rdf:about="http://www.search.net/mammals/hippopotamus">
    <ns2:name
xmlns:ns2="http://www.search.net/rdf#">Hippopotamus</ns2:name>
  </rdf:Description>
  <rdf:Seq rdf:about="http://www.search.net/main-search">
    <rdf:li rdf:resource="http://www.search.net/mammals"/>
  </rdf:Seq>
</rdf:RDF>

compared to the default
  $ rapper -q -o rdfxml input.rdf

As you can see, the namespaces get lost.  To set the namespaces on
output, there are API calls in the C/perl/python etc:

int raptor_serializer_set_namespace(raptor_serializer* serializer,
raptor_uri *uri, const char *prefix)
  Set a suggested namespace URI/prefix mapping for use in serializing.
   http://librdf.org/raptor/libraptor.html

On the command you can do that too:

  $ rapper -q -o rdfxml-abbrev -f
"xmlns:SEARCH='http://www.search.net/rdf#'" input.rdf

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:SEARCH="http://www.search.net/rdf#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Seq rdf:about="http://www.search.net/mammals">
    <rdf:li>http://www.search.net/mammals/lion</rdf:li>
    <rdf:li>http://www.search.net/mammals/hippopotamus</rdf:li>
    <SEARCH:name>Mammals</SEARCH:name>
  </rdf:Seq>
  <rdf:Description rdf:about="http://www.search.net/mammals/lion">
    <SEARCH:name>Lion</SEARCH:name>
  </rdf:Description>
  <rdf:Description
rdf:about="http://www.search.net/mammals/hippopotamus">
    <SEARCH:name>Hippopotamus</SEARCH:name>
  </rdf:Description>
  <rdf:Seq rdf:about="http://www.search.net/main-search">
    <rdf:li rdf:resource="http://www.search.net/mammals"/>
  </rdf:Seq>
</rdf:RDF>

Dave





More information about the redland-dev mailing list