Hi Collin,

A local element declaration is one which is declared within the scope [1] 
of a complex type definition. In your schema "author", "title", etc... are 
local element declarations. "catalog" is global. If an element declaration 
is local, getEnclosingCTDefinition() returns the XSComplexTypeDefinition 
for the enclosing complex type definition. What you were trying to find in 
the API is getTypeDefinition() [2] which returns the type definition 
(either simple or complex) for the element. If you're looking for a more 
comprehensive example on how to walk an XSModel take a look at the 
xni.PSVIWriter sample.

Thanks.

[1] http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#e-scope
[2] 
http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#XSElementDecl-typeDefinition

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

"Collin Chu" <[EMAIL PROTECTED]> wrote on 09/06/2006 02:54:17 AM:

> I'm a beginer of Xerces. I want to parse the following simple XML 
Schema:
> 
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
>   <xsd:element name="catalog"> 
>     <xsd:complexType>
>       <xsd:sequence>
>         <xsd:element name="book" 
>                      minOccurs="0" 
>                      maxOccurs="unbounded">
>            <xsd:complexType>
>               <xsd:sequence>
>                  <xsd:element name="author" type="xsd:string"/>
>                  <xsd:element name="title" type="xsd:string"/> 
>                  <xsd:element name="genre" type="xsd:string"/>
>                  <xsd:element name="price" type="xsd:float"/>
>                  <xsd:element name="publish_date" type="xsd:date"/> 
>                  <xsd:element name="description" type="xsd:string"/>
>               </xsd:sequence> 
>           </xsd:complexType>
>         </xsd:element> 
>       </xsd:sequence>
>       <xsd:attribute name="id" type="xsd:string"/>
>     </xsd:complexType>
>   </xsd:element>
> </xsd:schema>
> 
> When I used sample code " QueryXS.java",  it only listed the top-
> level element "catalog". I need to list all the elements defined in 
> the above schema. I added the code "XSElementDeclaration elem = 
> (XSElementDeclaration)map.item(i);" to capture the declaration of 
> element "catalog" after the following code in QueryXS.java:
>                 XSNamedMap map = model.getComponents(XSConstants.
> ELEMENT_DECLARATION);
>                 if (map.getLength() != 0) {
>                     System.out.
> println("*************************************************"); 
>                     System.out.println("* Global element 
> declarations: {namespace} name ");
>                     System.out.
> println("*************************************************");
>                     for (int i = 0; i < map.getLength(); i++) {
> But I don't know how to get complex type declaration of element 
> "catalog". I tried to use "getEnclosingCTDefinition()" of  class 
> "XSElementDeclaration", however, it returned "null", since the scope
> of "catalog" is global, not local (I don't know why). 
> 
> So, could any experts please tell me how to list all the elements of
> an XML Schema (please show me the corresponding code), and explain 
> the meaning of scope of element declaration. Thanks a lot. 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to