XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
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]
Re: [xml-dev] Extracting Schema from an element instance while parsing.

  Thanks.
After posting this post I did run into PSVIProvider and tried it out.
Voila ! It worked (probably better then my code !)
I felt so dumb ....

Except ... it only works while parsing XML not generating it.
In my use case I need access to the data while generating an XML 
document (from a different source),
so that I can extract the annotation information *before* generating a 
particular element (it will guide the decision on what to generate).
But using PSVIProvider, I might be able to do the same thing in 2 passes 
... not entirely sure yet, still looking.
Thanks for the suggestion.

There still is a use case (which I dont need yet but I think is useful).
That is, given a simplified XPath, find the XSD information - Without 
having an instance document.



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


On 9/14/2010 11:45 AM, Michael Glavassevich wrote:
>
> When you were evaluating Xerces' XML Schema API did you have a look at 
> PSVIProvider [1][2]? An XML Schema processor already has to match up 
> element declarations with elements in the instance. If you're 
> validating the document you can retrieve the XSElementDeclarations 
> from the PSVIProvider for each element and stream it if you're using SAX.
>
> Thanks.
>
> [1] 
> http://xerces.apache.org/xerces2-j/javadocs/xs/org/apache/xerces/xs/PSVIProvider.html
> [2] http://xerces.apache.org/xerces2-j/faq-xs.html#faq-8
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> David <dlee@calldei.com> wrote on 09/14/2010 10:56:00 AM:
>
> >   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
> >
> >
> > _______________________________________________________________________
> >
> > XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> > to support XML implementation and development. To minimize
> > spam in the archives, you must subscribe before posting.
> >
> > [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> > Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> > subscribe: xml-dev-subscribe@lists.xml.org
> > List archive: http://lists.xml.org/archives/xml-dev/
> > List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>


[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