locked
Astoria RDF support RRS feed

  • General discussion

  • Pablo's MIX 2007 presentation indicated that Astoria was looking at supporting RDF and he was looking for some feedback on the current RDF implementation.  I was glad to see that the Astoria team was thinking about RDF since more of my projects involve using RDF with our regional offices in Europe.  To-date Microsoft's support for RDF in .NET has been lacking.  When my projects require RDF I'm faced with the choice of either rolling my own RDF support or abandoning .NET for a Java solution which if frustrating.

     

    I have been investigating the RDF support in Astoria and think that the Astoria team is making its RDF support more difficult than it has to be.  RDF supports a feature called striping.  With RDF striping it is possible to make some minor alterations to your XML that would support your XML objectives and make your XML more friendly to RDF without resorting to raw RDF as the current implementation does.  Lets looks at the XML for the Northwind online sandbox:

     

    <DataService
     xml:base="http://astoria.sandbox.live.com/northwind/northwind.rse"
    >
      <NorthwindEntities uri=".">
        <Categories href="Categories" />
        <Customers href="Customers" />
        <Employees href="Employees" />
        <OrderLines href="OrderLines" />
        <Orders href="Orders" />
        <Products href="Products" />
        <Regions href="Regions" />
        <Shippers href="Shippers" />
        <Suppliers href="Suppliers" />
        <Territories href="Territories" />
      </NorthwindEntities>
    </DataService>

     

    The corresponding RDF for the Northwind online sandbox:

     

    <rdf:RDF
     xml:base="http://astoria.sandbox.live.com/northwind/northwind.rse"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    >
      <NorthwindEntities rdf:about=".">
        <rdf:Bag>
          <rdf:li rdf:resource="Categories" />
          <rdf:li rdf:resource="Customers" />
          <rdf:li rdf:resource="Employees" />
          <rdf:li rdf:resource="OrderLines" />
          <rdf:li rdf:resource="Orders" />
          <rdf:li rdf:resource="Products" />
          <rdf:li rdf:resource="Regions" />
          <rdf:li rdf:resource="Shippers" />
          <rdf:li rdf:resource="Suppliers" />
          <rdf:li rdf:resource="Territories" />
        </rdf:Bag>
      </NorthwindEntities>
    </rdf:RDF>

     

    With the use of RDF striping you can take the existing XML structure and add a few minor annotations.  The first change that is needed is the addition of an xmlns namespace for the DataService element since RDF requires all elements to be associated with a namespace.  Next the the RDF namespace will need to be declared on the DataService element.  The next change will be the addition of an rdf:parseType attribute on the NorthwindEntities element to indicate that it describes a resource rather than the default which is a property per the striping rules.  Lastly, all href attributes will be changed to use rdf:resource attributes.  The resulting RDF stripped XML is:

     

    <DataService
     xml:base="http://astoria.sandbox.live.com/northwind/northwind.rse"
     xmlns="http://astoria.sandbox.live.com/northwind/northwind.rse"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    >
      <NorthwindEntities rdf:parseType="Resource">
        <Categories rdf:resource="Categories" />
        <Customers rdf:resource="Customers" />
        <Employees rdf:resource="Employees" />
        <OrderLines rdf:resource="OrderLines" />
        <Orders rdf:resource="Orders" />
        <Products rdf:resource="Products" />
        <Regions rdf:resource="Regions" />
        <Shippers rdf:resource="Shippers" />
        <Suppliers rdf:resource="Suppliers" />
        <Territories rdf:resource="Territories" />
      </NorthwindEntities>
    </DataService>

     

    You will notice an additional difference between the current Astoria XML and the RDF striped XML.  The uri attribute has been dropped off the NorthwindEntities element.  This has to do with the RDF striping rules.  It's not clear, at this point in my investigation, whether the URI of the current entity is critical to Astoria's functionality.  However, if it is critical, then you can simply add an additional element level to the XML to satisify RDF's striping rules and change uri attributes to rdf:about attributes.

     

    <DataService
     xml:base="http://astoria.sandbox.live.com/northwind/northwind.rse"
     xmlns="http://astoria.sandbox.live.com/northwind/northwind.rse"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    >
      <Entity>
        <Northwind rdf:about=".">
          <Categories rdf:resource="Categories" />
          <Customers rdf:resource="Customers" />
          <Employees rdf:resource="Employees" />
          <OrderLines rdf:resource="OrderLines" />
          <Orders rdf:resource="Orders" />
          <Products rdf:resource="Products" />
          <Regions rdf:resource="Regions" />
          <Shippers rdf:resource="Shippers" />
          <Suppliers rdf:resource="Suppliers" />
          <Territories rdf:resource="Territories" />
        </Northwind>
      </Entity>
    </DataService>

     

    RDF striping provides some additional benefits over the current RDF implementation.  Each element becomes an RDF type, e.g., the Customers element is a type.  In the current implementation, the type information is being lost.  In some cases you will need to add an rdf:parseType with a value of Collection to an element.  This typically happens when you use the $expand query string option.

     

    With RDF striping you can support both your XML objective and your RDF objectives without resorting to emitting raw RDF.  The XML emitted as RDF striping maintains your existing struture which could also be constrained by an XML schema.  Basically, you add some additional namespaces and swap uri attributes for rdf:about, href attributes for rdf:resource and sprinkle rdf:parseType attributes with a value of either Resource or Collection where needed.

     

    Should the Astoria team decide not to integrate the current XML emitter with RDF striping could you please add an XML namespace to the DataService element, rather than having no namespace associated with the elements.

     

    As a side note, I noticed that the Astoria query string parameter are service level type attributes that interestingly have analogies in the OpenSearch and SRU standards.  I was wondering whether these standards influenced the Astoria's teams thinking in anyway.

     

     

    Andy.

     

    BTW, is any way to trick IE 7 into treating application/rdf+xml as an XML file so that it will display in the browser, instead of triggering a download dialog box?  Not sure why the IE 7 team didn't map application/*+xml to display in the browser by default.

    Thursday, July 26, 2007 6:38 AM