Hi Frank,
As far as I know, each element declaration is part of its parent element type definition. In your case you have to get the XSElementDecl object of the root element
I'm trying to implement the example code, found on the Xerces FAQ page for grammar parsing, http://xml.apache.org/xerces2-j/faq-grammars.html#faq-5, "examining grammars". When I access my XSModel, I can retrieve a named map with element declarations, but only the top-level-elements are listed. Can someone tell me, how to access these elements, which are located deeper in the hierarchy of the corresponding schema, i.e.:
How can I retrieve the XSObjects "page" or "subnet" using the XSModel and the associated methods? Any idea?
XSElementDecl parentElement = model.getElementDecl( "net", null );
Then you have to get the root type definition and its category:
XSTypeDefinition typeDef = parentElement.getTypeDefinition();
if( typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE )
{
//.....
}///////////////////////////////////////////////////////////////////////
else if( typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE )
{
//if complexType -> subelements possible
XSComplexTypeDecl complexTypeDef = (XSComplexTypeDecl) typeDef;
switch( complexTypeDef.getContentType() )
{
///////////////////////////////////////////////////////////////////
case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
{
//complexType with simple content: no subelements
// possible
}
///////////////////////////////////////////////////////////////////
case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
{
//complexType without any childelements
}
///////////////////////////////////////////////////////////////////
case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
{
XSParticleDecl[] particles = new XSParticleDecl[1];
particles[0] = (XSParticleDecl) complexTypeDef.getParticle();
//.....analyse particle
//this particle object can be a model group (like sequence, choice, all)
//or an element declaration (or an Wildcard)
//In your example it will be the sequence. This sequence references 2 particles objects, the 2
//element declarations of "page" and "subnet".
}
///////////////////////////////////////////////////////////////////
case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
{
XSParticleDecl[] particles = new XSParticleDecl[1];
particles[0] = (XSParticleDecl) complexTypeDef.getParticle();
//.....analyse particle
} }
Use this code to recurse the particle tree and get all child element declarations
...........
XSTerm term;
//Either model group, a wildcard, or an element declaration
for( int i=0; i<particles.length; i++ )
{
term = particles[ i ].getTerm();
switch( term.getType() )
{
///////////////////////////////////////////////////////////////////////
case XSConstants.ELEMENT_DECLARATION:
{
//this is the element declaration object e.g. for "page"
(XSElementDecl) term;
System.out.println( term.getName() ); //->e.g. "page"
}
break;
///////////////////////////////////////////////////////////////////////
case XSConstants.MODEL_GROUP:
{
XSModelGroupImpl modelGroup = (XSModelGroupImpl) term;
XSObjectListImpl objectList =
(XSObjectListImpl) modelGroup.getParticles();
int listLength = objectList.getLength();
XSParticleDecl[] particleList = new XSParticleDecl[ listLength ];
for( int a=0; a<listLength; a++ )
{
particleList[ a ] = (XSParticleDecl) objectList.getItem( a );
}
..............................
Kristian
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
