Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » getContentType() vs. getContent() on XSDComplexTypeDefinition
getContentType() vs. getContent() on XSDComplexTypeDefinition [message #597457] Mon, 09 January 2006 17:34
Eclipse UserFriend
Originally posted by:

Using org.eclipse.xsd, I'm looking to find all the valid child elements
for a given complex type, including anything inherited from base types.

I've already read the following thread: /msg01150.html

I can get what I need by recursively processing all the
XSDComplexTypeDefinitions, XSDParticles, and XSDModelGroups myself, but
isn't there an easy way to get all the valid types? The idea being, I
want to write a function that will check if a given element is valid under
a given type - regardless whether it is valid due to inherited types or

Here's some code that demonstrates my issues:

protected static void describe(XSDComplexTypeDefinition xctd){

// This prints only local attributes...
for(XSDAttributeUse xau :
System.out.println("@" + xau.getAttributeDeclaration().getName() + ",
" + xau);

// ... where this prints ALL valid attributes, both local and inherited
- good.
for(XSDAttributeUse xau :
System.out.println("@" + xau.getAttributeDeclaration().getName() + ",
" + xau);

// Now, I want to do the same thing with valid elements. Supposedly,
this is done with
// .getContent() (local) vs. .getContentType() (local + inherited).

if(xctd.getContentTypeCategory().getValue() ==
|| xctd.getContentTypeCategory().getValue() ==

// Both .getContentType() and .getContent() return an
// Iterating over their .eAllContents() or .eContents() all return one
empty XSDModelGroup.
// It seems that I need to be using the Term, correct? If so, more

XSDTerm term1 = ((XSDParticle)xctd.getContentType()).getTerm();
System.out.println("term1: " + term1); // Returns an XSDModelGroupImpl.

// Following produces a NullPointerException.
// XSDTerm term2 = ((XSDParticle)xctd.getContent()).getTerm();

XSDTerm term3 = xctd.getComplexType().getTerm();
System.out.println("term3: " + term3); // Returns the SAME
XSDModelGroupImpl as term1...
// - what is the difference?

XSDModelGroup xmg = (XSDModelGroup)term3;
for(XSDParticle part : (Iterable<XSDParticle>)xmg.getParticles()){
System.out.println("part: " + part); // part is a XSDParticleImpl
System.out.println("term: " + part.getTerm()); // term is another

// The BIG QUESTION: Where is my list of valid elements??


Previous Topic:XSD:How to extract xsd:simpleContent ?
Next Topic:getContentType() vs. getContent() on XSDComplexTypeDefinition
Goto Forum:

Current Time: Sat Jan 16 03:49:44 GMT 2021

Powered by FUDForum. Page generated in 0.02359 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top