OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Extracting Schema from an element instance while parsing.

  I finally bit the bullet after finding no simple way to do this.   I 
have succeeded in using the Apache XML Schema API


The use case is while parsing *or generating* an XML document, given the 
current element, return the XSD information for that element.
In my case I'm mainly interested in Annotation data but as a 'side 
effect' I'm able now to get the XSElementDeclaration (and other related 

Possibly just me, but I found it amazingly non-obvious how to do this 
seemingly simple task.
I found it easy enough to load the schema and ask for any 'top level 
element declaration'.
But in the face of a more complex schema with substitution groups and 
local type/element declarations its entirely non-obvious.

However, I believe I have succeeded , atlesast with my few test cases.  
(non-trival xml schemas with type derivation, substitution groups and 
local declarations).

Right now I'm using StAX to validate that I dont have to have a DOM tree 
instance to do this.   With StAX I am able to read an XML stream and at 
every StartElement event get the coresponding XSD XSElementDeclaration.
Furthermore, I can do the reverse.  That is while *writing XML* , at any 
given point I can query the coresponding XSD information given a 
namespace URI and localname.

The code I'm experimenting with doesnt rely on StAX at all, thats just 
one use case.  Internally it relies on the "path" to an element.
That is, it maintains a stack of open elements generated by a sequence 
of pushElement(qname)/popElement().
Thus in theory one could take a simple XPath expression   
/foo/bar/spam/bletch   and access the same data.

I'm certainly not sure if I'm interpreting the XSD Model 100% correctly 
but it appears to work so far, and I'm gaining confidence that its not 
fundamentally wrong (i.e. I could fix it if I find problems, and my 
fairly complex test case appears to be working).

So my question to the group is this:  Given that I've seen this type of 
question asked many times before, and have myself been unable to find 
any existing libraries that do this.

Before I embark on *specializing* this code to my own ends ... I'm 
considering *generalizing* it ...

Q)  Is there any interest in a library of this sort ?
Q) Is there any interest in more easy-to-use "commands" that could do 
something with this feature ?
Q) What could one do with this ? -> In my case I want to extract 
annotation elements from a given instance element (or attribute).
-- Are there other generally useful tasks given an API  that can match 
instance objects to XSD objects  ?

And finally
Q) Am I re-inventing the wheel ? And if so why couldn't I find the wheel 
before ? :)


David A. Lee

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS