<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.