Lloyd,

Once you have an element...you can easily get it's type by using the
reasonably named method called "getType".

XMLType type = elem.getType();
if (type != null) {
   if (type.isSimpleType()) {
      ...
   }
   else if (type.isComplexType()) {
      ...
   }
}

Using schema#getComplexTypes() will only return top-level complex types.

--Keith


Lloyd Rochester wrote:
> 
> I am new to Castor and am trying to traverse a schema the following way
> (wrong I assume):
> 
> SchemaReader reader = new SchemaReader(new 
> FileReader("someSchema.xsd"),"someSchema.xsd");
> Schema       schema = reader.read();
> Vector elementsV = new Vector(); /* a vector to put my ElementDecl's in */
> 
> for (Enumeration e = schema.getElementDecls(); e.hasMoreElements();) {
>         elementsV.add(e.nextElement());
>         ElementDecl elem =  (ElementDecl) elementsV.lastElement();
>         System.out.println( "Element: " + elem.getName() );
> 
>         if(elem.getType().isComplexType()) {
>                 System.out.println( "\tType: Complex");
>                 ComplexType temp = schema.getComplexType(elem.getName());
>                 /* temp is always null */
>                 }
>                 else System.out.println( "\tType: Simple");
> 
>                 if(elem.hasChildren()) System.out.println( "\tHas Children");
>                 else                 System.out.println( "\tHas no Children");
>          }
> }
> 
> I have read a response to a mail where Keith Visco instructed to use
> ComplexType#enumerate, although I cannot find out how to get the complex
> types the schema contains.  Once I have the ElementDecl's I can find no
> way to return the ComplexType (if the ElementDecl has a ComplexType).
> All I would like to do is traverse the schema finding the complex types
> and their group definitions, atts, etc ....
> 
> If I am to do:
>  Enumeration e = schema.getComplexTypes()
> 
> The enumeration is empty. I am stuck, can anyone instruct me on the
> proper methods to use to traverse a schema?
> 
> Here is a very simple schema I have been using:
> 
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
> <xs:element name="person">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="full_name" type="xs:string"/>
>       <xs:element name="nick_name" type="xs:string" maxOccurs="10" minOccurs="0"/>
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>
> </xs:schema>
> 
> How can I traverse this and determine element person is a complex type,
> with a sequence of two elements named full_name, and nick_name that need
> strings?
> 
> Thank you
> 
> Lloyd
> 
> -----------------------------------------------------------
> 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

Reply via email to