[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Extracting Schema from an element instance while parsing.

  • From: David <dlee@calldei.com>
  • To: xml-dev@lists.xml.org
  • Date: Tue, 14 Sep 2010 10:56:00 -0400

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

http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040122/
http://xerces.apache.org/xerces2-j/javadocs/xs/index.html

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

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


-- 
David A. Lee
dlee@calldei.com
http://www.xmlsh.org



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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.