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 #65756] Mon, 09 January 2006 17:34 Go to next message
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!!
Re: getContentType() vs. getContent() on XSDComplexTypeDefinition [message #65783 is a reply to message #65756] Tue, 10 January 2006 16:34 Go to previous messageGo to next message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
Mark Ziesemer wrote:

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

Hi Mark,

There's no simple way to get a list of the valid element because the
content model of schema allows subtleties that can't be expressed in a
simple list.

Simple example (off the top of my head - please forgive any typos):

.....
<xsd:complexType name="foo">
<xsd:sequence>
<xsd:element name="a" .../>
<xsd:choice>
<xsd:element name="b" .../>
<xsd:element name="c" .../>
</xsd:choice>
<xsd:element name="d" .../>
</xsd:sequence>
</xsd:complexType>
.....

So, in type "foo", is "b" a valid element? Sure, but that's not a very
useful answer, since it's *only* valid after "a", before "d", and to the
exclusion of "c".

So, inheritence is really the least of your problems. ;) And, yes,
it's handled for you by getContentType().

Anyway, to usefully interpret the information in the schema, you really
need to be able to navigate the content model, which is what XSD allows
you to do.

I'm not sure how to address your specific questions. I'd need to see
the schema in order to guess what your code should be doing.

My overall comment is that one can almost never spend too much time
trying to understand the concrete and abstract models of XML schema. The
Rose models (reproduced as images in the XSD Javadoc) can help, but the
best source of information is really the schema recommendation, itself.

Cheers,
Dave
Re: getContentType() vs. getContent() on XSDComplexTypeDefinition [message #65805 is a reply to message #65783] Tue, 17 January 2006 14:14 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Mark,

Using XSDParticle.getDFA you can get a state machine that can
validate/accept a sequence of elements (namespace/name pairs). Maybe
that will help with what you are trying to implement?


Dave Steinberg wrote:

> Mark Ziesemer wrote:
>
>> 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.
>
>
> Hi Mark,
>
> There's no simple way to get a list of the valid element because the
> content model of schema allows subtleties that can't be expressed in a
> simple list.
>
> Simple example (off the top of my head - please forgive any typos):
>
> ....
> <xsd:complexType name="foo">
> <xsd:sequence>
> <xsd:element name="a" .../>
> <xsd:choice>
> <xsd:element name="b" .../>
> <xsd:element name="c" .../>
> </xsd:choice>
> <xsd:element name="d" .../>
> </xsd:sequence>
> </xsd:complexType>
> ....
>
> So, in type "foo", is "b" a valid element? Sure, but that's not a
> very useful answer, since it's *only* valid after "a", before "d", and
> to the exclusion of "c".
>
> So, inheritence is really the least of your problems. ;) And, yes,
> it's handled for you by getContentType().
>
> Anyway, to usefully interpret the information in the schema, you
> really need to be able to navigate the content model, which is what
> XSD allows you to do.
>
> I'm not sure how to address your specific questions. I'd need to see
> the schema in order to guess what your code should be doing.
>
> My overall comment is that one can almost never spend too much time
> trying to understand the concrete and abstract models of XML schema.
> The Rose models (reproduced as images in the XSD Javadoc) can help,
> but the best source of information is really the schema
> recommendation, itself.
>
> Cheers,
> Dave
Re: getContentType() vs. getContent() on XSDComplexTypeDefinition [message #597464 is a reply to message #65756] Tue, 10 January 2006 16:34 Go to previous message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
Mark Ziesemer wrote:

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

Hi Mark,

There's no simple way to get a list of the valid element because the
content model of schema allows subtleties that can't be expressed in a
simple list.

Simple example (off the top of my head - please forgive any typos):

.....
<xsd:complexType name="foo">
<xsd:sequence>
<xsd:element name="a" .../>
<xsd:choice>
<xsd:element name="b" .../>
<xsd:element name="c" .../>
</xsd:choice>
<xsd:element name="d" .../>
</xsd:sequence>
</xsd:complexType>
.....

So, in type "foo", is "b" a valid element? Sure, but that's not a very
useful answer, since it's *only* valid after "a", before "d", and to the
exclusion of "c".

So, inheritence is really the least of your problems. ;) And, yes,
it's handled for you by getContentType().

Anyway, to usefully interpret the information in the schema, you really
need to be able to navigate the content model, which is what XSD allows
you to do.

I'm not sure how to address your specific questions. I'd need to see
the schema in order to guess what your code should be doing.

My overall comment is that one can almost never spend too much time
trying to understand the concrete and abstract models of XML schema. The
Rose models (reproduced as images in the XSD Javadoc) can help, but the
best source of information is really the schema recommendation, itself.

Cheers,
Dave
Re: getContentType() vs. getContent() on XSDComplexTypeDefinition [message #597475 is a reply to message #65783] Tue, 17 January 2006 14:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Mark,

Using XSDParticle.getDFA you can get a state machine that can
validate/accept a sequence of elements (namespace/name pairs). Maybe
that will help with what you are trying to implement?


Dave Steinberg wrote:

> Mark Ziesemer wrote:
>
>> 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.
>
>
> Hi Mark,
>
> There's no simple way to get a list of the valid element because the
> content model of schema allows subtleties that can't be expressed in a
> simple list.
>
> Simple example (off the top of my head - please forgive any typos):
>
> ....
> <xsd:complexType name="foo">
> <xsd:sequence>
> <xsd:element name="a" .../>
> <xsd:choice>
> <xsd:element name="b" .../>
> <xsd:element name="c" .../>
> </xsd:choice>
> <xsd:element name="d" .../>
> </xsd:sequence>
> </xsd:complexType>
> ....
>
> So, in type "foo", is "b" a valid element? Sure, but that's not a
> very useful answer, since it's *only* valid after "a", before "d", and
> to the exclusion of "c".
>
> So, inheritence is really the least of your problems. ;) And, yes,
> it's handled for you by getContentType().
>
> Anyway, to usefully interpret the information in the schema, you
> really need to be able to navigate the content model, which is what
> XSD allows you to do.
>
> I'm not sure how to address your specific questions. I'd need to see
> the schema in order to guess what your code should be doing.
>
> My overall comment is that one can almost never spend too much time
> trying to understand the concrete and abstract models of XML schema.
> The Rose models (reproduced as images in the XSD Javadoc) can help,
> but the best source of information is really the schema
> recommendation, itself.
>
> Cheers,
> Dave
Previous Topic:getContentType() vs. getContent() on XSDComplexTypeDefinition
Next Topic:creating ecore model from editable model
Goto Forum:
  


Current Time: Mon Dec 22 12:46:50 GMT 2014

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

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