Warning:
This wiki has been archived and is now read-only.

XSDinRDFXML

From OWL
Jump to: navigation, search

Using an Inline Datatype in RDF/XML

Background

RDF/XML uses rdf:parseType="Literal" to embed XML Literals into RDF.

This syntactic construct uses XML Exclusive Canonicalization (XC14N) to remove the variability of XML serialization. This canonicalization determines the visability of XML namespace declarations. Only those namespace declarations that are visibly used in element or attribute names are preserved.

Some XML applications, in particular XML Schema, use qnames in attribute values. Such uses are not visible in the terms of XC14N. Thus if there is no visible use, applying XC14N to such applications loses required namespace bindings, and the two XML technologies are incompatible.

Three sample user defined XML Schema Datatypes

Please note, I am very happy to be corrected by someone more knowledgeable. I have not written this sort of code in anger.

Here is an unnamed datatype that might be used to pick out 5 seconds of a video stream.

 <xs:simpleType
    xmlns:xs="http://www.w3.org/2001/XMLSchema" >
   <xs:restriction base="xs:decimal">
     <xs:minInclusive value="305.200" />
     <xs:maxInclusive value="310.199" />
   </xs:restriction>
 </xs:simpleType>

Actually, I am really thinking of an underlying number system that counts the number of milliseconds, so that the following user-defined datatype would be helpful, which perhaps, could be defined in some other file, or in an external XML Schema designed for such video data.

 <xs:schema 
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          targetNamespace="http://example.org/myDatatypes" >
   <xs:simpleType name="precision3" id="precision3">
     <xs:restriction base="xs:decimal">
       <xs:pattern value="[0-9]*.[0-9]{3}" >
       </xs:pattern>
     </xs:restriction>
   </xs:simpleType>
 </xs:schema>

Note: I might have got the pattern syntax wrong, I've not checked.

Now, given this user defined datatype, the following unnamed type seems better (i.e. more precise) than my first attempt.

 <xs:simpleType
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:my="http://example.org/myDatatypes" >
   <xs:restriction base="my:precision3">
     <xs:minInclusive value="305.200" />
     <xs:maxInclusive value="310.199" />
   </xs:restriction>
 </xs:simpleType>

Using the first unnamed datatypes in RDF/XML

A piece of RDF/XML like:

 <owl:Class ID="ActionTime" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    <owl:equivalentClass>
       <owl:Restriction>
         <owl:onProperty rdf:resource="#hasTime"/>
         <owl:someValuesFrom rdf:parseType="Literal">
           <xs:simpleType>
            <xs:restriction base="xs:decimal">
             <xs:minInclusive value="305.200" />
             <xs:maxInclusive value="310.199" />
            </xs:restriction>
           </xs:simpleType>
         </owl:someValuesFrom>
       </owl:Restriction>
     </owl:equivalentClass>
  </owl:Class>

is ok (from an RDF/XML, XC14N and an XML Schema point of view). From an OWL point of view whether that is an appropriate serialization of the datatype I don't know. We might prefer:


 <owl:Class ID="ActionTime" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    <owl:equivalentClass>
       <owl:Restriction>
         <owl:onProperty rdf:resource="#hasTime"/>
         <owl:someValuesFrom>
           <owl:DataRange>
              <owl:withXMLSchema rdf:parseType="Literal">
                 <xs:simpleType>
                   <xs:restriction base="xs:decimal">
                    <xs:minInclusive value="305.200" />
                    <xs:maxInclusive value="310.199" />
                   </xs:restriction>
                 </xs:simpleType>
              </owl:withXMLSchema>
            </owl:DataRange>
         </owl:someValuesFrom>
       </owl:Restriction>
     </owl:equivalentClass>
  </owl:Class>

Either of these have the following properties:

  1. The base="xs:decimal" attribute, uses the qname xs:decimal in its value, being an invisible use of the namespace prefix xs:.
  2. The namespace prefix xs: is also visibly used, on the element tag xs:restriction
  3. XC14N includes the inherited namespace declaration for xs:, because of the visible use.
  4. The literal value, can be understood by an XML Schema processor, because every qname in an attribute value, has an associated namespace declaration.


Using the last unnamed datatypes in RDF/XML

A piece of RDF/XML like:

 <owl:Class ID="ActionTime" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    <owl:equivalentClass>
       <owl:Restriction>
         <owl:onProperty rdf:resource="#hasTime"/>
         <owl:someValuesFrom rdf:parseType="Literal">
           <xs:simpleType>
            <xs:restriction base="my:precision3"  
               xmlns:my="http://example.org/myDatatypes">
             <xs:minInclusive value="305.200" />
             <xs:maxInclusive value="310.199" />
            </xs:restriction>
           </xs:simpleType>
         </owl:someValuesFrom>
       </owl:Restriction>
     </owl:equivalentClass>
  </owl:Class>

is not ok (from an RDF/XML, XC14N and an XML Schema point of view).

This, or any variant, has the following properties.

  1. The base="my:precision3" attribute, uses the qname my:precision3 in its value, being an invisible use of the namespace prefix my:.
  2. The namespace prefix my: is not visibly used.
  3. XC14N discards the namespace declaration for my:, because it is not visibly used.
  4. The literal value, cannot be understood by an XML Schema processor, because the qname my:precision3 in an attribute value, has no associated namespace declaration.

Summary

There are some constraints for using in-line XML Schema within RDF/XML, using the rdf:parseType="Literal" construct.