<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xml:base="http://www.w3.org/1999/02/22-rdf-syntax-ns"
	>

  <xs:annotation>
    <xs:documentation>
	    <div xmlns="http://www.w3.org/1999/xhtml">
		    <h1>XML Schema for RDF</h1>
		    <p>$Id: rdf.xsd,v 1.17 2000/08/04 14:37:44 swick Exp $</p>

		    <p>originally derived from <a
				    href="http://www.oasis-open.org/cover/xmlSchemaForRDF.html">Rick J's
				    work</a>:
		    </p>

		    <pre>
			    From:      Rick JELLIFFE &lt;ricko@allette.com.au>
			    To:        xml-dev@xml.org
			    Subject:   Re: new public working draft of XML Schema
			    Date:      Sat, 26 Feb 2000 23:05:20 +0800
		    </pre>

		    <p>then modified to match 
			    <a href="http://www.w3.org/TR/1999/REC-rdf-syntax-19990222/#grammar">the RDF formal grammar</a></p>

		    <blockquote>
			    <p>created 2000-12-25,               <br />
				    Rick Jelliffe,
				    <br />
				    Academia Sinica Computing Centre.  <br />
				    Thanks to Henry Thompson for help.  </p>
			    <p>RDF Specification at
				    <a href="http://www.w3.org/TR">W3C</a>.
			    </p>
		    </blockquote>
		    <p>Later, taken from http://www.w3.org/2001/XMLSchema and updated</p>
	    </div>
    </xs:documentation>
  </xs:annotation>

  <xs:attribute name="datatype" type="xs:string" />

  <!-- Top-level of RDF Document -->
  <xs:element name="RDF">
    <xs:complexType>
      <xs:sequence  maxOccurs="unbounded" >
        <xs:group ref="obj"/> <!-- abstract -->
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:group name="obj">
    <xs:choice>
      <xs:element ref="typedNode"/>
      <xs:group ref="container"/>
    </xs:choice>
  </xs:group>

  <!-- @@check this after doing typednode -->
  <xs:element name="Description"
           type="typedNodeType" />


  <xs:group name="container">
    <!-- @@ spec says you can subclass this, but that
         makes parsing depend on schema info. Bad. -->
    <xs:choice>
      <xs:element ref="Bag"/>
      <xs:element ref="Seq"/>
      <xs:element ref="Alt"/>
    </xs:choice>
  </xs:group>

  <xs:attributeGroup name="idAboutAttrOpt">
    <xs:annotation><xs:documentation source="http://www.w3.org/TR/1999/REC-rdf-syntax-19990222/#aboutAttr"/></xs:annotation>
    <xs:attributeGroup ref="aboutAttrOpt"/>
    <xs:attributeGroup ref="idAttrOpt"/>
    <!-- @@leave out aboutEachAttr for now -->

  </xs:attributeGroup>

  <xs:attribute name="ID" type="xs:ID" />
  <!--
  -->

  <xs:attributeGroup name="idAttrOpt">
    <xs:attribute ref="ID" use='optional'/>
  </xs:attributeGroup>

  <xs:attribute name="about" type="xs:anyURI" />
  <xs:attributeGroup name="aboutAttrOpt">
    <xs:attribute name="about" use='optional' type="xs:anyURI" />
    <xs:attribute ref="about" use='optional' />
  </xs:attributeGroup>

  <!-- leaving out aboutEachAttr for now @@-->

  <!-- leaving out bagIdAttr @@-->

  <!-- leaving out propAttr @@-->

  <!-- leaving out typeAttr @@-->

  <xs:element name="propertyElt" abstract="true"
           type="propertyEltType" />

  <xs:complexType name="propertyEltType">
	  <xs:annotation>
		  <xs:documentation>this is a "union type"; use
			  xsi:type in the instance to discriminate between concrete subtypes
		  </xs:documentation>
	  </xs:annotation>
  </xs:complexType>

  <xs:complexType name="propertyEltValue">
    <xs:attributeGroup ref="idAttrOpt"/>
  </xs:complexType>

  <xs:complexType name="propertyEltLiteral">
    <xs:sequence>
      <xs:any minOccurs="0" processContents="skip"/>
    </xs:sequence>
    <xs:attributeGroup ref="idAttrOpt"/>
    <!--
    TODO cxsd complains if I don't comment this out:
    "Member with multiple types: parseType"
    <xs:attributeGroup ref="parseLiteral"/>
    -->
  </xs:complexType>

  <xs:complexType name="propertyEltResource">
    <xs:sequence maxOccurs="unbounded" >
      <xs:element ref="propertyElt"   /><!--abstract !-->
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="propertyEltRef">
    <xs:attributeGroup ref="idRefAttrOpt"/>
    <!-- @@leaving out bagIdAttr? -->
    <!-- @@leaving out propAttr* -->
  </xs:complexType>

  <xs:element name="typedNode" abstract="true"
	   type="typedNodeType"/>

  <xs:complexType name="typedNodeType">
    <xs:sequence maxOccurs="unbounded">
      <xs:element ref="propertyElt"/>
    </xs:sequence>
    <xs:attributeGroup ref="idAboutAttrOpt"/>
    <!--@@leaving out bagidattr, propattr -->
  </xs:complexType>

  <xs:attributeGroup name="idRefAttrOpt">
    <xs:attributeGroup ref="idAttrOpt"/>
    <xs:attributeGroup ref="resourceAttrOpt"/>
  </xs:attributeGroup>

 <!--@@ can complex types be abstract? or just elements? -->
  <xs:complexType name="value" abstract="true"/>

  <xs:complexType name="valueObj">
    <xs:group ref="obj"/>
  </xs:complexType>

  <xs:complexType name="valueString">
    <xs:sequence/> <!-- no subelements -->
  </xs:complexType>

  <xs:attribute name="resource" type="xs:anyURI" />
  <xs:attributeGroup name="resourceAttrOpt">
    <xs:attribute name="resource" use='optional' type="xs:anyURI" />
    <xs:attribute ref="resource" use='optional' />
  </xs:attributeGroup>

  <xs:attributeGroup name="resourceAttr">
    <!-- @@er... which one to require? -->
    <xs:attribute name="resource" use='optional' type="xs:anyURI" />
    <xs:attribute ref="resource" use='optional' />
  </xs:attributeGroup>

  <xs:element name="Seq" type="members"/>
  <xs:element name="Bag" type="members"/>
  <xs:element name="Alt" type="members"/>
  <!-- @@restrict Alt to have at least one member -->

  <xs:complexType name="members">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="li" type="item"/>
    </xs:sequence>
    <xs:attributeGroup ref="idAttrOpt"/>
    <!-- @@leaving out memberAttr* -->
  </xs:complexType>

  <xs:complexType name="item">
	  <xs:annotation>
		  <xs:documentation>this is a "union type"; use
			  xsi:type in the instance to discriminate between concrete subtypes.
			  @@hmm... can I mark this as "abstract" somehow?
		  </xs:documentation>
	  </xs:annotation>
  </xs:complexType>

  <xs:complexType name="referencedItem">
   <xs:attributeGroup ref="resourceAttr"/>
  </xs:complexType>

  <!-- @@strictly speaking, inlineItem should be
       specified as subtypes, one of propertyEltValue,
       propertyEltLiteral, and propertyEltResource,
       with use="prohibited" on some attributes to
       get rid of them. But I'm gonna skip it for now -->

  <!--
  <xs:attribute name="parseType"/>
  -->
  <xs:attributeGroup name="parseLiteral">
    <xs:attribute name="parseType" fixed="Literal" />
    <!--
    <xs:attribute ref="parseType" fixed="Literal" />
    -->
  </xs:attributeGroup>

  <xs:attributeGroup name="parseResource">
    <xs:attribute name="parseType"  fixed="Resource" />
    <!--
    <xs:attribute ref="parseType"  fixed="Resource" />
    -->
  </xs:attributeGroup>

  <!-- so much for syntax structure. Now for the particular
       properties and classes... -->

  <xs:element name="Statement"
	   type="typedNodeType" />

  <xs:element name="Property"
           type="typedNodeType" />

	   <!-- these are is constrained to use resource="...";
		use xsi:type to do something else -->
  <xs:element name="subject"
	   type="propertyEltRef" />

  <xs:element name="predicate"
	   type="propertyEltRef" />

  <xs:element name="object"
	   type="propertyEltRef" />

  <xs:element name="type"
	   type="propertyEltRef" />

  <!-- constrained to the <value>...</value> syntax -->
  <xs:element name="value"
	   type="valueString" />

</xs:schema>
