OK, Werner: you asked for it ;-)

It may also be for my benefit: I hope someone can suggest how to improve this. As a solution, all that speaks for it is that it works. Elegant, it is not. What I *wanted* to do was define the RDF schema and only have references from the the DC schema
to the RDF one. The way it worked out, each references the other. Eugh.

OK. First of all the DC schema, because it's alright in itself.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
xmlns:dc="http://purl.org/dc/elements/1.1/"; targetNamespace="http:// purl.org/dc/elements/1.1/">

        <xsd:annotation>
<xsd:documentation xml:lang="en" source="http://xml.vimia.com/cms/ sitetree/meta-dc.xsd"> Based on dcmes-dc.xsd from www.dublincore.org and modified to allow processing with
                        Castor. </xsd:documentation>
        </xsd:annotation>

<!-- note this reference to the RDF schema: it's a backward reference, so I would regard it
                as kosher. -->

        <!-- Import the RDF namespace schema for rdf:resource -->
        <xsd:import namespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
                schemaLocation="meta-rdf.xsd" />

        <!-- this is not necessary: all the following complexTypes could extend
                rdf:commonType directly, but it gives me an abstract class in 
Java
                which will be useful as a supertype of all the other DC classes 
-->

        <xsd:complexType name="abstractRoot" abstract="true">
                <xsd:complexContent>
                        <xsd:extension base="rdf:commonType"> </xsd:extension>
                </xsd:complexContent>
        </xsd:complexType>

        <!-- I define different types for each kind of element -->

        <xsd:complexType name="titleType">
                <xsd:complexContent>
                        <xsd:extension base="dc:abstractRoot"> </xsd:extension>
                </xsd:complexContent>
        </xsd:complexType>
        
        <xsd:complexType name="creatorType">
                <xsd:complexContent>
                        <xsd:extension base="dc:abstractRoot"> </xsd:extension>
                </xsd:complexContent>
        </xsd:complexType>
        
<!-- and as many further types as are needed to support the DC types -->

        <!-- define an element for each kind of DC tag -->

        <xsd:element name="title" type="dc:titleType" />

        <xsd:element name="creator" type="dc:creatorType" />

        <!-- and as many further element definitions as are needed ... -->

</xsd:schema>


Now for the nasty RDF schema, which unfortunately references the DC schema:


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
        xmlns:dc="http://purl.org/dc/elements/1.1/";
        targetNamespace="http://www.w3.org/1999/02/22-rdf-syntax-ns#";>

        <xsd:annotation>
<xsd:documentation xml:lang="en" source="http://xml.vimia.com/cms/ sitetree/meta-rdf.xsd"> Based on dcmes-rdf.xsd from www.dublincore.org and modified to allow processing
                        with Castor.
                </xsd:documentation>
        </xsd:annotation>


        <!-- Import the XML namespace schema for xml:lang -->
        <xsd:import namespace="http://www.w3.org/XML/1998/namespace";
                schemaLocation="http://www.w3.org/2001/xml.xsd"; />

<!-- this is a forward reference to the DC schema, which contains a backward reference to here. If this were the only inelegant bit, it would be OK. But see below for worst stuff... -->
        
        <!-- Import the namespace schema for dc:* -->
<xsd:import namespace="http://purl.org/dc/elements/1.1/"; schemaLocation="meta-dc.xsd" />

        <xsd:element name="RDF">
                <xsd:complexType>
                        <xsd:sequence>
<xsd:element ref="rdf:Description" minOccurs="0" maxOccurs="unbounded"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
        
<!-- this is horrible. Description belongs to the RDF namespace, so that element is in the right place here. But the references to stuff from the DC namespace is awful. If substitutionGroups
                worked, the DC stuff could be encapsulated in the DC schema -->

        <xsd:element name="Description">
                <xsd:complexType>
                        <xsd:choice minOccurs="0" maxOccurs="unbounded">
                                <xsd:element ref="dc:title" />
                                <xsd:element ref="dc:creator" />
                                <!-- etc --->
                        </xsd:choice>
                        <xsd:attribute ref="rdf:about" use="optional" />
                </xsd:complexType>
        </xsd:element>

        <xsd:complexType name="commonType">
                <xsd:attribute ref="xml:lang" use="optional" />
                <xsd:attribute ref="rdf:resource" use="optional" />
        </xsd:complexType>
        
        <xsd:attribute name="about" type="xsd:anyURI" />

        <xsd:attribute name="resource" type="xsd:anyURI" />

</xsd:schema>

There are other permutations which are valid XML, but this is the only solution I have found which Castor's source generator works with. If there are any XSD wizards out there who would like to
comment, I'd be very grateful for the feedback.

If there's any way that the source generator could be made to handle substitutionGroups, the above
would be a lot cleaner.

Regards
Steve


On 8 May 2006, at 20:50, Werner Guttmann wrote:

Yes, please .. ;-). For the benefit of everybody else, please do so ... ;-).

Werner

Stephen Winnall wrote:
I've found a solution to this problem. It's not pretty, but it seems to
work. If anyone is interested in the details, I'll
post the two schemas.

Steve

On 7 May 2006, at 18:16, Stephen Winnall wrote:

When you have documents which contain multiple namespaces, is there a way to define XML Schemas so that Castor can handle those documents? I
want to be able to read documents like the following:

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF PUBLIC "-//DUBLIN CORE//DCMES DTD 2002/07/31//EN"

"http://dublincore.org/documents/2002/07/31/dcmes-xml/dcmes-xml- dtd.dtd">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
         xmlns:dc="http://purl.org/dc/elements/1.1/";>
  <rdf:Description
rdf:about="http://www.ilrt.bristol.ac.uk/people/cmdjb/";>
    <dc:title>Dave Beckett's Home Page</dc:title>
    <dc:creator>Dave Beckett</dc:creator>
    <dc:publisher>ILRT, University of Bristol</dc:publisher>
    <dc:date>2002-07-31</dc:date>
  </rdf:Description>
</rdf:RDF>

Yup, it's Dublin Core again ;-)  Clearly two schemas are needed, one
for the RDF (rdf:) and one for the DC (dc:) namespace. The schemas
from the Dublin Core website for handling this stuff work perfectly in Oxygen when I compose example files, but since they make extensive use of substitution groups, the Castor source generator cannot handle them.

I've spent some time trying to produce Castor-friendly schemas
equivalent to the official ones, but I don't seem to be getting
anywhere. This is due on the one hand to my limited knowledge of XML
Schema, but I am beginning to wonder whether there is a way to do this
with Castor.

Can anyone give me some guidance on this, please?

Steve


-------------------------------------------------
If you wish to unsubscribe from this list, pleasesend an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, pleasesend an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to