[Nml-wg] xml list examples

Freek Dijkstra Freek.Dijkstra at sara.nl
Sat Dec 4 05:59:06 CST 2010


Jeroen van der Ham wrote:

>> Freek/Jeroen: what does RDF do (or would could RDF do) to do the same thing?

> I've personally not used it before, but accoding to the RDF schema there
> are the following options (see example below):
> - rdf:Bag containing numbered items (rdf:_1, rdf:_2, ...) which are
> actually taken as unordered items.
> - rdf:Bag containing unnumbered items like HTML lists (rdf:li)
> - rdf:Seq contains unnumbered items like HTML lists (rdf:li), which are
> supposed to be read in order.
> 
> I must say I'm a bit amazed by the last option since XML doesn't seem to
> support ordering.
> 
> For completeness, there's also a rdf:Alt class for providing alternate
> options, which also uses rdf:li

Could you verify the above statements?
[RDF Schema] says there is no syntactic difference between the three
"Containers" (rdf:Bag, rdf:Seq and rdf:Alt). They can use both numbered
items (rdf:_1, rdf:_2, ...) as well as unnumbered items (rdf:li).
The rdf:li concept seem to have been developed after some issues with
the use of "special names" (rdf:_1, rdf:_2) [RDF-collection-issues]

In addition, rdf also supports "Collections" (rdf:List) which does not
use the above, but uses rdf:first, rdf:rest and rdf:nil to make an
ordered list of elements. (Note that I personally find the actual
implementation of rdf:List very convoluted; see figure 16 of
[RDF-Primer]: instead of simply defining a rdf:next or so that points to
the next element, you must use rdf:rest to point to some vague
intermediate thing, and then rdf:first to point to the actual element)

I'm very curious what is recommend use (rdf:Container with rdf:_1,
rdf:_2,...; rdf:Container with rdf:li; or rdf:Collection with
rdf:first/rdf:rest), and if it is possible to translate between
Containers and Collections.

Here are two examples of rdf:Containers, and one of rdf:Collection
(examples 17 to 19 of [RDF-Syntax], although I have rewritten example
19. The XML example uses some shorthand syntax using
rdf:parseType="Collection", which I find difficult to grasp, so I just
translated the more explicit n3 syntax to XML)

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Seq rdf:about="http://example.org/favourite-fruit">
    <rdf:_1 rdf:resource="http://example.org/banana"/>
    <rdf:_2 rdf:resource="http://example.org/apple"/>
    <rdf:_3 rdf:resource="http://example.org/pear"/>
  </rdf:Seq>
</rdf:RDF>

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Seq rdf:about="http://example.org/favourite-fruit">
    <rdf:li rdf:resource="http://example.org/banana"/>
    <rdf:li rdf:resource="http://example.org/apple"/>
    <rdf:li rdf:resource="http://example.org/pear"/>
  </rdf:Seq>
</rdf:RDF>

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:ex="http://example.org/stuff/1.0/">
  <rdf:Description rdf:about="http://example.org/basket">
    <ex:hasFruit>
      <rdf:first rdf:about="http://example.org/banana"/>
      <rdf:rest>
        <rdf:first rdf:about="http://example.org/apple"/>
        <rdf:rest>
          <rdf:first rdf:about="http://example.org/pear"/>
          <rdf:rest>
            <rdf:nil />
          </rdf:rest>
        </rdf:rest>
      </rdf:rest>
    </ex:hasFruit>
  </rdf:Description>
</rdf:RDF>

(FYI, the original example 19 follows, which is exactly the same RDF,
but with shorthand XML, which is easy to read, but hides the details,
and seems to rely on the ordering in XML.)
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:ex="http://example.org/stuff/1.0/">
  <rdf:Description rdf:about="http://example.org/basket">
    <ex:hasFruit rdf:parseType="Collection">
      <rdf:Description rdf:about="http://example.org/banana"/>
      <rdf:Description rdf:about="http://example.org/apple"/>
      <rdf:Description rdf:about="http://example.org/pear"/>
    </ex:hasFruit>
  </rdf:Description>
</rdf:RDF>

References:

[RDF-schema] http://www.w3.org/TR/rdf-schema/#ch_othervocab
[RDF-collection-issues] See
http://www.w3.org/2000/03/rdf-tracking/#rdfms-seq-representation and
http://www.w3.org/2000/03/rdf-tracking/#rdf-containers-otherapproaches
[RDF-Primer] http://www.w3.org/TR/rdf-primer/#othercapabilities
[RDF-syntax]
http://www.w3.org/TR/REC-rdf-syntax/#section-Syntax-list-elements


Regards,
Freek


More information about the nml-wg mailing list