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: mark_z.charter.net

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:
http://dev.eclipse.org/newslists/news.eclipse.technology.xsd /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
not.

Here's some code that demonstrates my issues:

protected static void describe(XSDComplexTypeDefinition xctd){

// This prints only local attributes...
for(XSDAttributeUse xau :
(Iterable<XSDAttributeUse>)xctd.getAttributeContents()){
System.out.println("@" + xau.getAttributeDeclaration().getName() + ",
" + xau);
}

// ... where this prints ALL valid attributes, both local and inherited
- good.
for(XSDAttributeUse xau :
(Iterable<XSDAttributeUse>)xctd.getAttributeUses()){
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() ==
XSDContentTypeCategory.ELEMENT_ONLY
|| xctd.getContentTypeCategory().getValue() ==
XSDContentTypeCategory.MIXED){

// Both .getContentType() and .getContent() return an
XSDComplexTypeContent.
// 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
questions:

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
XSDModelGroupImpl

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

}
}

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


Current Time: Mon Dec 22 00:37:07 GMT 2014

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

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