Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Querying parents of element declarations
Querying parents of element declarations [message #630732] Mon, 04 October 2010 17:49 Go to next message
Matt  is currently offline Matt
Messages: 2
Registered: October 2010
Junior Member
Hi all,

I am trying to use the Eclipse XSD API to query a XSD schema and to not only understand whether a given element qname is allowed in a schema but also under what contexts (e.g. parent elements). I am able to do the first part via a call to (I am using v2.6.0 of the XSD API):

EList<XSDElementDeclaration> list = schema.getElementDeclarations();

However, I have not been able to figure out whether there are "convenience methods" that make it possible to know where a given element is allowed (either optional or required).

As further background, I am writing this as standalone code and it will not be used via a UI.

Does anyone have any advice even if it means that more code is necessary to build a custom data structure to account for context? Thanks for the help.

Matt
Re: Querying parents of element declarations [message #630785 is a reply to message #630732] Tue, 05 October 2010 00:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
Matt,

Comments below.


Matt wrote:
> Hi all,
>
> I am trying to use the Eclipse XSD API to query a XSD schema and to
> not only understand whether a given element qname is allowed in a
> schema but also under what contexts (e.g. parent elements). I am able
> to do the first part via a call to (I am using v2.6.0 of the XSD API):
>
> EList<XSDElementDeclaration> list = schema.getElementDeclarations();
>
> However, I have not been able to figure out whether there are
> "convenience methods" that make it possible to know where a given
> element is allowed (either optional or required).
I'm not sure what you mean.
>
> As further background, I am writing this as standalone code and it
> will not be used via a UI.
>
> Does anyone have any advice even if it means that more code is
> necessary to build a custom data structure to account for context?
You can look at XSDPrototypicalSchema as an example of how to construct
pretty much everything.
> Thanks for the help.
>
> Matt
Re: Querying parents of element declarations [message #630876 is a reply to message #630785] Tue, 05 October 2010 12:34 Go to previous messageGo to next message
Matt  is currently offline Matt
Messages: 2
Registered: October 2010
Junior Member
>> However, I have not been able to figure out whether there are
>> "convenience methods" that make it possible to know where a given
>> element is allowed (either optional or required).
>I'm not sure what you mean.

If element "X" allows "Y" as a child, I want to be able to form a data structure that allows me to ask (programatically) "where is X allowed as a child?" or, similarly, if I ask "is Z allowed as a child of X?", the answer is "false".

As far as I can tell, the XSD API is lower-level than that...so I'm asking for help in how to "walk" the XSD data model starting with the element declarations provided by the "getElementDeclarations" call to XSDSchema.

I've seen the code for XSDPrototypicalSchema.java, and it helped me to get to where I'm at now, but it only deals with loading/printing/serializing of the model and not "walking" the data model. Are there other sets of example/sample code?

Thanks.

Matt
Re: Querying parents of element declarations [message #630913 is a reply to message #630876] Tue, 05 October 2010 14:46 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
Matt,

Have you looked at the model diagrams in the Javadoc? In general,
methods like EObject.eAllContents walk the containment tree, so you'll
want to have a look at that. Also in general, you can ask any EObject
for it's eClass() and from that EClass you can use
getEAllStructureFeatures to determine what features are available on the
object. I.e., there's a model you can query dynamically at runtime; the
same one that's shown in the model diagrams for your static analysis.


Matt wrote:
>>> However, I have not been able to figure out whether there are
>>> "convenience methods" that make it possible to know where a given
>>> element is allowed (either optional or required).
>> I'm not sure what you mean.
>
> If element "X" allows "Y" as a child, I want to be able to form a data
> structure that allows me to ask (programatically) "where is X allowed
> as a child?" or, similarly, if I ask "is Z allowed as a child of X?",
> the answer is "false".
>
> As far as I can tell, the XSD API is lower-level than that...so I'm
> asking for help in how to "walk" the XSD data model starting with the
> element declarations provided by the "getElementDeclarations" call to
> XSDSchema.
>
> I've seen the code for XSDPrototypicalSchema.java, and it helped me to
> get to where I'm at now, but it only deals with
> loading/printing/serializing of the model and not "walking" the data
> model. Are there other sets of example/sample code?
>
> Thanks.
>
> Matt
Previous Topic:XML parsers
Next Topic:Cross-referencing namespaces & schemas
Goto Forum:
  


Current Time: Tue Sep 16 13:42:11 GMT 2014

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

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