Hi Arnaud,
Thanks for you help.
Here is a simple example of my problem (sorry I dont think
that I expressed my problem well in words before, but hope
these files and output will make more sense). Ok, these are
the attachments:
1) ReadSchema.java
2) TestSchema.java
3) 2 schema versions (imsvdex_1.xsd, imsvdex_2.xsd)
4) output.txt
* I am sure you know this*, but I thought I will mention that you
will also require "xercesImpl.jar" when running the program.
The "output.txt" shows the outputs when using the 2 different
versions of the same schema.
Thank you,
Tina
> Hi Tyna,
>
> I've just tried the example with the CVS version of Castor and it is
> working fine for me. Can you please post the code you are using?
>
> Arnaud
> > -----Original Message-----
> > From: Tina Manoharan [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, August 26, 2003 3:18 PM
> > To: [EMAIL PROTECTED]
> > Subject: [castor-dev] Element -> ComplexContent -> Extension
> >
> >
> >
> > Hello All,
> >
> > There is an element "elem1" with complexType "type1" in
> > my schema as shown below:
> >
> > 1)
> > <xs:element name="elem1" block="#all">
> > <xs:complexType>
> > <xs:complexContent>
> > <xs:extension base="type1"/>
> > </xs:complexContent>
> > </xs:complexType>
> > </xs:element>
> >
> >
> > 2)
> > <xs:complexType name="type1">
> > <xs:sequence>
> > <-----elements & attributes---->
> > </xs:sequence>
> > </xs:complexType>
> >
> >
> >
> > Now, when I do
> >
> > XMLType xmlType = elementDecl.getType();
> >
> >
> > The xmlType is "null".
> >
> >
> > However, if the schema is changed to:
> >
> > 1) <xs:element name="elem1" type="type1" block="#all"/>
> >
> > Then it works fine, I get the xmlType and it also identifies
> > as ComplexType.
> >
> > But, I would like to know if there is a way I can get
> > the complexType from the original schema. Please help
> > me with this problem.
> >
> > Thank you,
> > Tina
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
> >
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>
--
-----------------------------------------------
Dr. Tina Manoharan
Research Associate, ICBL, Rm. G41,
Heriot Watt University, Edinburgh EH14 4AS, UK.
Tel: (+44) 131 451 3280, (+44) 7740 959483
Web: http://www.macs.hw.ac.uk/~ceetm2
-----------------------------------------------
// ReadSchema.java
import java.util.*;
import java.io.*;
import org.exolab.castor.xml.schema.*;
import org.exolab.castor.xml.schema.reader.*;
public class ReadSchema
{
Schema schema;
SchemaReader reader;
String rootName = "vdex";
public ReadSchema(String schemaFile)
{
try
{
reader = new SchemaReader(schemaFile);
schema = reader.read();
}
catch(IOException io) {System.out.println("IOException when reading
schema!!");}
ElementDecl rootElementDecl = schema.getElementDecl(rootName);
System.out.println("rootElementDecl Name = " +
rootElementDecl.getName());
getChildren(rootElementDecl);
}
public void getChildren(ElementDecl root)
{
XMLType xmlType = root.getType();
System.out.println("xmlType = " + root.getType() + " xmlType Name = " +
xmlType.getName());
// If Complex Type build children
if(xmlType instanceof ComplexType)
{
ComplexType complexType = (ComplexType) xmlType;
System.out.println("complexType name = " + complexType.getName());
// Build/Add sub-group child structures
Enumeration cTypeBits = complexType.enumerate();
while(cTypeBits.hasMoreElements())
{
Structure structure = (Structure)
cTypeBits.nextElement();
switch(structure.getStructureType())
{
case Structure.GROUP:
System.out.println("Structure GROUP");
buildChildGroup((Group) structure);
break;
default:
System.out.println("Other ComplexType Structure: " +
structure.toString());
}
}
}
}
protected void buildChildGroup(Group group)
{
Enumeration groupMembers = group.enumerate();
while(groupMembers.hasMoreElements())
{
Particle particle = (Particle)groupMembers.nextElement();
switch(particle.getStructureType())
{
// Another Element Decl
case Structure.ELEMENT:
System.out.println("Group particle: ELEMENT");
addChildElementDecl((ElementDecl)particle);
break;
default:
System.out.println("Group Particle: " + particle.toString());
} // switch
} // while
}
protected void addChildElementDecl(ElementDecl childElementDecl)
{
System.out.println("childElementDecl name = " + childElementDecl.getName());
}
}// TestSchema.java
public class TestSchema
{
static String schemaFile = "imsvdex_1.xsd";
// static String schemaFile = "imsvdex_2.xsd";
public static void main(String[] args)
{
ReadSchema readSchema = new ReadSchema(schemaFile);
}
}<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Adam Richard Cooper (FD
Learning Ltd) -->
<xs:schema targetNamespace="http://www.imsglobal.org/xsd/imsvdex_v1p0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.imsglobal.org/xsd/imsvdex_v1p0" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.0 Public Draft">
<xs:element name="vdex" block="#all">
<xs:complexType>
<xs:complexContent>
<xs:extension base="vdexType"/>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="metadata" type="metadataType" block="#all"/>
<xs:element name="langstring" type="langstringType" block="#all"/>
<xs:element name="caption" type="langstringBag" block="#all"/>
<xs:element name="description" type="descriptionType" block="#all"/>
<xs:element name="term" type="termType" block="#all"/>
<xs:element name="relationship" type="relationshipType" block="#all">
</xs:element>
<xs:element name="mediaDescriptor" type="mediaDescriptorType" block="#all"/>
<xs:element name="mediaLocator" type="mediaLocatorType" block="#all"/>
<xs:simpleType name="vdexProfilesType">
<xs:restriction base="xs:string">
<xs:enumeration value="lax"/>
<xs:enumeration value="hierarchicalTokenTerms"/>
<xs:enumeration value="flatTokenTerms"/>
<xs:enumeration value="glossaryOrDictionary"/>
<xs:enumeration value="thesaurus"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="identifierType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="mediaLocatorType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="mediaDescriptorType">
<xs:sequence>
<xs:element ref="mediaLocator"/>
<xs:element name="interpretationNote" type="descriptionType"
block="#all" minOccurs="0"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="relationshipType">
<xs:sequence>
<xs:element name="targetTerm" type="identifierType"
block="#all"/>
<xs:element name="relationshipType" type="vocabType"
block="#all" minOccurs="0"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="termType">
<xs:sequence>
<xs:element name="termIdentifier" type="identifierType"
block="#all"/>
<xs:element ref="caption" minOccurs="0"/>
<xs:element ref="description" minOccurs="0"/>
<xs:element ref="mediaDescriptor" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="relationship" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="metadata" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="term" minOccurs="0" maxOccurs="unbounded"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="orderSignificant" type="xs:boolean"
default="false"/>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="metadataType">
<xs:sequence>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="vdexType">
<xs:sequence>
<xs:element name="vocabName" type="langstringBag" block="#all"
minOccurs="0">
</xs:element>
<xs:element name="vocabIdentifier" type="vocabIdentifierType"
block="#all" minOccurs="0">
</xs:element>
<xs:element ref="term" maxOccurs="unbounded"/>
<xs:element ref="metadata" minOccurs="0"
maxOccurs="unbounded"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="orderSignificant" type="xs:boolean"
default="false"/>
<xs:attribute name="profileType" type="vdexProfilesType"
use="optional" default="lax"/>
<xs:attribute name="language" type="xs:language" use="optional"/>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="langstringType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language"
use="optional"/>
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="langstringBag">
<xs:sequence>
<xs:element ref="langstring" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="vocabType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="source" type="xs:anyURI"
use="required"/>
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="descriptionType">
<xs:complexContent>
<xs:extension base="langstringBag"/>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="vocabIdentifierType">
<xs:simpleContent>
<xs:extension base="identifierType">
<xs:attribute name="isRegistered" type="xs:boolean"
default="false"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.4 U (http://www.xmlspy.com) by Adam Richard Cooper (FD
Learning Ltd) -->
<xs:schema targetNamespace="http://www.imsglobal.org/xsd/imsvdex_v1p0"
xmlns="http://www.imsglobal.org/xsd/imsvdex_v1p0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.0 Public Draft">
<xs:element name="vdex" type="vdexType" block="#all"/>
<xs:element name="metadata" type="metadataType" block="#all"/>
<xs:element name="langstring" type="langstringType" block="#all"/>
<xs:element name="caption" type="langstringBag" block="#all"/>
<xs:element name="description" type="langstringBag" block="#all"/>
<xs:element name="term" type="termType" block="#all"/>
<xs:element name="relationship" type="relationshipType" block="#all"/>
<xs:element name="mediaDescriptor" type="mediaDescriptorType" block="#all"/>
<xs:element name="mediaLocator" type="mediaLocatorType" block="#all"/>
<xs:simpleType name="vdexProfilesType">
<xs:restriction base="xs:string">
<xs:enumeration value="lax"/>
<xs:enumeration value="hierarchicalTokenTerms"/>
<xs:enumeration value="flatTokenTerms"/>
<xs:enumeration value="glossaryOrDictionary"/>
<xs:enumeration value="thesaurus"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="identifierType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="mediaLocatorType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="mediaDescriptorType">
<xs:sequence>
<xs:element ref="mediaLocator"/>
<xs:element name="interpretationNote" type="langstringBag"
block="#all" minOccurs="0"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="relationshipType">
<xs:sequence>
<xs:element name="targetTerm" type="identifierType"
block="#all"/>
<xs:element name="relationshipType" type="vocabType"
block="#all" minOccurs="0"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="termType">
<xs:sequence>
<xs:element name="termIdentifier" type="identifierType"
block="#all"/>
<xs:element ref="caption" minOccurs="0"/>
<xs:element ref="description" minOccurs="0"/>
<xs:element ref="mediaDescriptor" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="relationship" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="metadata" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element ref="term" minOccurs="0" maxOccurs="unbounded"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="orderSignificant" type="xs:boolean"
default="false"/>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="metadataType">
<xs:sequence>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="vdexType">
<xs:sequence>
<xs:element name="vocabName" type="langstringBag" block="#all"
minOccurs="0"/>
<xs:element name="vocabIdentifier" type="vocabIdentifierType"
block="#all" minOccurs="0"/>
<xs:element ref="term" maxOccurs="unbounded"/>
<xs:element ref="metadata" minOccurs="0"
maxOccurs="unbounded"/>
<xs:any namespace="##other" processContents="strict"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="orderSignificant" type="xs:boolean"
default="false"/>
<xs:attribute name="profileType" type="vdexProfilesType"
use="optional" default="lax"/>
<xs:attribute name="language" type="xs:language" use="optional"/>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="langstringType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language"
use="optional"/>
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="langstringBag">
<xs:sequence>
<xs:element ref="langstring" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute namespace="##other" processContents="strict"/>
</xs:complexType>
<xs:complexType name="vocabType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="source" type="xs:anyURI"
use="required"/>
<xs:anyAttribute namespace="##other"
processContents="strict"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="vocabIdentifierType">
<xs:simpleContent>
<xs:extension base="identifierType">
<xs:attribute name="isRegistered" type="xs:boolean"
default="false"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
// (1)
// Output when filename = "imsvdex_1.xsd"
rootElementDecl Name = vdex
xmlType = [EMAIL PROTECTED] xmlType Name = null
complexType name = null
// (2)
// Output when filename = "imsvdex_2.xsd"
rootElementDecl Name = vdex
xmlType = [EMAIL PROTECTED] xmlType Name = vdexType
complexType name = vdexType
Structure GROUP
Group particle: ELEMENT
childElementDecl name = vocabName
Group particle: ELEMENT
childElementDecl name = vocabIdentifier
Group particle: ELEMENT
childElementDecl name = term
Group particle: ELEMENT
childElementDecl name = metadata
Group Particle: [EMAIL PROTECTED]