|Querying parents of element declarations [message #630732]
||Mon, 04 October 2010 13:49
Registered: October 2010
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.
|Re: Querying parents of element declarations [message #630913 is a reply to message #630876]
||Tue, 05 October 2010 10:46
| Ed Merks
Registered: July 2009
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.
>>> 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
> 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?
Powered by FUDForum
. Page generated in 0.01527 seconds